JS implementation of timestamps and time-date conversions:
The conversion of timestamps and time dates is a common operation, and the following is an example of how you can convert between them by code examples.
It is recommended that you refer to the introduction to the date () constructor parameter in JavaScript in advance.
I. Time-date conversion to timestamp:
Now there's a time date: "2013/5/12 20:10:20", which is converted to a timestamp form:
The code is as follows:
var datestr= "2013/5/12 20:10:20"; var date=New date (DATESTR); Console.log (Date.gettime ());
Use the gettime () function to get the timestamp of a specified time-date object, as described in the GetTime () method section of the JavaScript Date object .
In fact, there are many other methods, here is not introduced, just need to know this way can be, others can accumulate slowly.
Two. Time stamp conversion to event date:
Example code one:
var date=New date (1368360620000); Console.log (date.tolocalestring ());
For more information, refer to the tolocalestring () method section of the JavaScript Date object .
Example two:
functionFormatDate (now) {varYear=now.getyear (); varMonth=now.getmonth (+1); varDate=now.getdate (); varHour=now.gethours (); varMinute=now.getminutes (); varSecond=now.getseconds (); returnyear+ "-" +month+ "-" +date+ "" +hour+ ":" +minute+ ":" +second; } varD=NewDate (1368360620000); Console.log (FormatDate (d));
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=11849
For more information, refer to: http://www.softwhy.com/javascript/
JS implementation timestamp and time-date conversion