javascript日期time_ t转换 [英] javascript date time_ t conversion
问题描述
我从数据库中获取一个秒数(以time_t格式)的日期(例如1364565600)
现在我要将此日期转换为日,月,日(例如星期二,3月18日)
我希望这是可能的。
timestart:function (time_start){
///////////////////////////
////// code转换//////
return time_start;
}
提前感谢
将您获得的秒数乘以1000,并使用一个新的Date()对象,该对象需要毫秒作为参数(基于与time_t相同的想法,即秒,从Date()是基于毫秒):
timestart:function(time_start){
return new Date(1000 * time_start);
}
要从中获取Date字符串,请使用.toDateString()。还有一些其他方法可以用来抓取日期信息并将其转换为所需的类型,您可以在这里找到它们: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date
I'm having a problem with the date format in javascript. I'm getting a date in seconds (in time_t format) from a database (ex. 1364565600) Now I want to convert this date to day, month, day (ex. Tuesday, March, 18th).
I hope this is possible.
timestart: function (time_start) {
///////////////////////////////
//////code for conversion//////
return time_start;
}
Thanks in advance!
Multiply the seconds you're getting by 1000 and use a new Date() object, which takes milliseconds as a parameter (which is based on the same idea as time_t, which is seconds since epoch, but Date() is based on milliseconds):
timestart: function (time_start) {
return new Date(1000 * time_start);
}
To get the Date string from it, use .toDateString(). There are a few other methods you could use to grab the date information and convert it to the types you want, you can find them here: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date
这篇关于javascript日期time_ t转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!