628c2a9b6c0da3623558b7454b4f704d2c61c064
[platform/framework/web/crosswalk-tizen.git] /
1 # time #
2
3 Utilities for time manipulation.
4
5
6 ## convert(value, sourceUnit, [destinationUnit]):Number
7
8 Converts time between units.
9
10 Available units: `millisecond`, `second`, `minute`, `hour`, `day`, `week`.
11 Abbreviations: `ms`, `s`, `m`, `h`, `d`, `w`.
12
13 We do **not** support year and month as a time unit since their values are not
14 fixed.
15
16 The default `destinationUnit` is `ms`.
17
18 ```js
19 convert(1, 'minute');    // 60000
20 convert(2.5, 's', 'ms'); // 2500
21 convert(2, 'm', 's');    // 120
22 convert(500, 'ms', 's'); // 0.5
23 ```
24
25
26
27 ## now():Number
28
29 Returns the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.
30 Uses `Date.now()` if available.
31
32 ### Example
33
34 ```js
35 now(); // 1335449614650
36 ```
37
38
39
40 ## parseMs(ms):Object
41
42 Parse timestamp (milliseconds) into an object `{milliseconds:number,
43 seconds:number, minutes:number, hours:number, days:number}`.
44
45 ### Example
46
47 ```js
48 // {days:27, hours:4, minutes:26, seconds:5, milliseconds:454}
49 parseMs(2348765454);
50 ```
51
52
53
54 ## toTimeString(ms):String
55
56 Convert timestamp (milliseconds) into a time string in the format "[H:]MM:SS".
57
58 ### Example
59
60 ```js
61 toTimeString(12513);   // "00:12"
62 toTimeString(951233);  // "15:51"
63 toTimeString(8765235); // "2:26:05"
64 ```