showing results for - "javascript human readable date and time converter"
Christopher
28 Sep 2018
1
2var ts = new Date();
3console.log(ts.toDateString());
4# Thu Sep 02 2021
5
6console.log(ts.toGMTString());
7# Thu, 02 Sep 2021 02:36:02 GMT
8
9console.log(ts.toISOString());
10# 2021-09-02T02:36:02.097Z
11
12console.log(ts.toJSON());
13# 2021-09-02T02:36:02.097Z
14
15console.log(ts.toLocaleDateString());
16# 9/2/2021
17
18console.log(ts.toLocaleTimeString());
19# 2:36:02 PM
20
21console.log(ts.toLocaleString());
22# 9/2/2021, 2:36:02 PM
23
24console.log(ts.toString());
25# Thu Sep 02 2021 14:36:02 GMT+1200 (New Zealand Standard Time)
26
27console.log(ts.toTimeString());
28# 14:36:02 GMT+1200 (New Zealand Standard Time)
29
30console.log(ts.toUTCString());
31# Thu, 02 Sep 2021 02:36:02 GMT
32
33
34
35
36var functions = ["toDateString", "toGMTString", "toISOString", "toJSON", "toLocaleDateString", "toLocaleTimeString", "toLocaleString", "toString", "toTimeString", "toUTCString"];
37var ts = new Date();
38var code = $("#jsExample");
39for (i in functions) {
40	fun = functions[i];
41	code.append("console.log(ts." + fun + "());\n");
42	code.append("# " + ts[fun]() + "\n\n");
43
44	console.log(fun);
45}
46