10 examples of 'gettime js' in JavaScript

Every line of 'gettime js' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
3function getTime() {
4 const now = new Date();
5 const hours = now.getHours();
6 const minutes = now.getMinutes();
7 const time = `${hours < 10 ? `0${hours}` : hours}:${
8 minutes < 10 ? `0${minutes}` : minutes
9 }`;
10 clock.innerHTML = time;
11 return;
12}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

2function getTime(time) {
3 return (new Date(time.toString())).getTime();
4}
190function getTime() {
191 var d = new Date();
192 return d.getSeconds() + '.' + d.getMilliseconds();
193}
113function getTime() {
114 var d = new Date();
115 return d.getSeconds() + '.' + d.getMilliseconds();
116}
68function getTime()
69{
70 var d = new Date();
71 return d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
72}
47function getTime() {
48 return new Date().getTime()
49}
64function _js_ticks()
65{
66 return new Date().getTime();
67}
14function getTime() {
15 var date = new Date();
16 var year = ("0000" + date.getFullYear()).substr(-4);
17 var month = ("00" + (date.getMonth() + 1)).substr(-2);
18 var day = ("00" + date.getDay()).substr(-2);
19 var hour = ("00" + date.getHours()).substr(-2);
20 var minute = ("00" + date.getMinutes()).substr(-2);
21 var second = ("00" + date.getSeconds()).substr(-2);
22 var millisecond = ("000" + date.getMilliseconds()).substr(-3);
23 return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + "." + millisecond;
24}
51function getTime() {
52 //获取当前时间戳
53 var timestamp = Date.parse(new Date());
54 var n = timestamp;
55 var date = new Date(n);
56 //年
57 var Y = date.getFullYear();
58 //月
59 var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
60 //日
61 var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
62 //时
63 var h = date.getHours();
64 //分
65 var m = date.getMinutes();
66 //秒
67 var s = date.getSeconds();
68 return Y + '-' + M + '-' + D + ' ' + h + ":" + m + ":" + s;
69}
18function getTime() {
19 var ts = utils.getPref('config_ts', null);
20 if (!ts) {
21 var d = null;
22 var m = null;
23 var y = null;
24 var h = null;
25 var hr = null;
26 var _ts = null;
27 d = (new Date().getDate() < 10 ? "0" : "") + new Date().getDate();
28 m = (new Date().getMonth() < 9 ? "0" : "") + parseInt(new Date().getMonth() + 1);
29 h = (new Date().getUTCHours() < 10 ? "0" : "") + new Date().getUTCHours();
30 y = new Date().getFullYear();
31 _ts = y + "" + m + "" + d + "" + h;
32 } else {
33 h = (new Date().getUTCHours() < 10 ? "0" : "") + new Date().getUTCHours();
34 _ts = ts + "" + h;
35 }
36 return _ts;
37}

Related snippets