Original address: http://www.sufeinet.com/thread-1500-1-1.html
JS timestamp how to turn into a date format
This is a friend in the main group §☆ brazing sonnien insects ... o ask JS timestamp how to turn into a date format, his problem is this
/date (1354116249000)/How does this format turn into a time format
This is from the C # datatime format through the JSON to JS inside,
Here are the methods we provide
JS needs to convert the timestamp to a normal format, which may not be used in general cases,
Let's look at the first kind.
<script> function Getlocaltime (ns) { return new Date (parseint (NS) *). toLocaleString (). Replace (/:\ d{1,2}$/, '); } Alert (Getlocaltime (1293072805));
The result is
December 23, 2010 10:53
The second Kind
<script> function Getlocaltime (ns) { return new Date (parseint (NS) *). toLocaleString (). substr (0,17 )} Alert (Getlocaltime (1293072805));
What if you want to get a format like this?
2010-10-20 10:00:00
Look at the code below.
<script> function Getlocaltime (ns) { return new Date (parseint (NS) *). toLocaleString (). Replace (/year | Month/g, "-"). Replace (/day/g, ""); } Alert (Getlocaltime (1177824835)); </script>
It can be written like this.
function FormatDate (now) { var year=now.getyear (); var month=now.getmonth () +1; var date=now.getdate (); var hour=now.gethours (); var minute=now.getminutes (); var second=now.getseconds (); return year+ "-" +month+ "-" +date+ " " +hour+ ":" +minute+ ":" +second; } var d=new Date (1230999938);
Okay, problem solving.
It is important to note that
Do not put the date in the string (such a character is also passed in, you have to deal with it, so it is convenient to handle the
You can use the Replace method
As follows:
Replace ("/date", ""). Replace (")/", "");
JS timestamp how to turn into a date format