javascript日期time_ t转换 [英] javascript date time_ t conversion

查看:133
本文介绍了javascript日期time_ t转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在javascript中遇到日期格式问题。
我从数据库中获取一个秒数(以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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆