-
-
Save Ivlyth/c4921735812dd2c0217a to your computer and use it in GitHub Desktop.
var d = new Date(); | |
d = new Date(d.getTime() - 3000000); | |
var date_format_str = d.getFullYear().toString()+"-"+((d.getMonth()+1).toString().length==2?(d.getMonth()+1).toString():"0"+(d.getMonth()+1).toString())+"-"+(d.getDate().toString().length==2?d.getDate().toString():"0"+d.getDate().toString())+" "+(d.getHours().toString().length==2?d.getHours().toString():"0"+d.getHours().toString())+":"+((parseInt(d.getMinutes()/5)*5).toString().length==2?(parseInt(d.getMinutes()/5)*5).toString():"0"+(parseInt(d.getMinutes()/5)*5).toString())+":00"; | |
console.log(date_format_str); | |
//2015-03-31 13:35:00 |
works like charm!!. Thanks
For UTC...
I tried yours and it was giving a fixed time for some odd reason.
function NOW() {
var date = new Date();
var aaaa = date.getUTCFullYear();
var gg = date.getUTCDate();
var mm = (date.getUTCMonth() + 1);
if (gg < 10)
gg = "0" + gg;
if (mm < 10)
mm = "0" + mm;
var cur_day = aaaa + "-" + mm + "-" + gg;
var hours = date.getUTCHours()
var minutes = date.getUTCMinutes()
var seconds = date.getUTCSeconds();
if (hours < 10)
hours = "0" + hours;
if (minutes < 10)
minutes = "0" + minutes;
if (seconds < 10)
seconds = "0" + seconds;
return cur_day + " " + hours + ":" + minutes + ":" + seconds;
}
console.log(NOW());
Credits:
dotmaui.com
naryad
When formatting the time you are rounding every 5 minutes.
For example, 23:59 becomes 23:55.
@rcebrian yes, i'm rounding the time every 5 minutes because some reason.
@glenwell because i'm rounding time every 5mins, so you will see fixed time when you execute the code in a small duration (say 11:01 and 11:04, you see only 11:00)
Why not to use this one
const formatedTimestamp = ()=> {
const d = new Date()
const date = d.toISOString().split('T')[0];
const time = d.toTimeString().split(' ')[0];
return `${date} ${time}`
}
https://gist.github.com/mohokh67/e0c5035816f5a88d6133b085361ad15b
@mohokh67 because of this:
You could, of course, correct the offset and then use that method.
Why not to use this one
const formatedTimestamp = ()=> { const d = new Date() const date = d.toISOString().split('T')[0]; const time = d.toTimeString().split(' ')[0]; return `${date} ${time}` }https://gist.github.com/mohokh67/e0c5035816f5a88d6133b085361ad15b
😎
Why not to use this one
const formatedTimestamp = ()=> { const d = new Date() const date = d.toISOString().split('T')[0]; const time = d.toTimeString().split(' ')[0]; return `${date} ${time}` }https://gist.github.com/mohokh67/e0c5035816f5a88d6133b085361ad15b
Thank you very much!!
😋
const ISO = (timeStamp=Date.now()) => {
return new Date(timeStamp - (new Date().getTimezoneOffset() * 60 * 1000)).toISOString().slice(0,-5).split('T')
}
console.log('one->',ISO(new Date('2020-09-26 11:28:55').getTime()))
console.log('now->',ISO())
one-> [ '2020-09-26', '11:28:55' ]
now-> [ '2021-09-26', '20:13:36' ]
这个也行吧?new Date().toLocaleString().replaceAll("/", "-")
问这个问题得大概率都是国内的吧🤣
这个也行吧?new Date().toLocaleString().replaceAll("/", "-") 问这个问题得大概率都是国内的吧🤣
简单好用 中国人不骗中国人🤣
var f_s_ymd_hms = function(n_unix_ts_ms){
var o_date = new Date(n_unix_ts_ms);
var s_hms_ymd = `${o_date.getFullYear().toString().padStart(2,'0')}-${(o_date.getMonth()+1).toString().padStart(2,'0')}-${o_date.getDate().toString().padStart(2,'0')} ${o_date.getHours().toString().padStart(2,'0')}:${o_date.getMinutes().toString().padStart(2,'0')}:${o_date.getSeconds().toString().padStart(2,'0')}`
}
const now = new Date()
const [date, time] = now.toISOString().substring(0, 19).split('T')
return \`${date} ${time}\`
import {
f_b_daylight_saving_time,
f_s_isotimezone__from_s_timezone,
f_s_ymd__from_n_ts_ms_utc,
f_s_dmy__from_n_ts_ms_utc,
f_s_hms__from_n_ts_ms_utc,
f_s_ymd_hms__from_n_ts_ms_utc,
f_n_ms_offset_from_s_timezone_n_ts_ms,
f_o_ts_range__day__from_n_ts_ms_utc,
f_o_ts_range__week__from_n_ts_ms_utc,
f_o_ts_range__month__from_n_ts_ms_utc,
f_o_ts_range__year__from_n_ts_ms_utc,
f_s_timestring_from_n_ms,
f_measure_time,
f_n_ts_ms__rounded_to
}
from "https://deno.land/x/[email protected]/mod.js"
Or ...
const getUTCTimestamp = ()=> {
const d = new Date().toISOString().split('T')
const date = d[0];
const time = d[1].split('.')[0];
return `${date} ${time}`
}
const [date, time] = now.toISOString().substring(0, 19).split('T')
this is clean(est) cheers
Works Perfect!