Now there is a situation: back in the background to give me a January 1, 1970 to the current number of seconds, and then I need to convert the number of seconds to years and days, I think of some methods are considered to be too complex trouble, want to ask you have any good points of the method or ideas?
Reply content:
Now there is a situation: back in the background to give me a January 1, 1970 to the current number of seconds, and then I need to convert the number of seconds to years and days, I think of some methods are considered to be too complex trouble, want to ask you have any good points of the method or ideas?
Direct code
Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt;}//调用new Date(time).Format("yyyy-MM-dd hh:mm");
var d = new Date(1463068800 * 1000);alert(d.toISOString());
1463068800
That is, unix
time stamps. The above method can be converted directly to the js
time in.
var d = new Date ()
D.settime (seconds * 1000);
var year = D.getfullyear ();
Var...
You can get everything you want, date and year.
Use Moment.js directly, easy to understand http://momentjs.cn/
Using Moment.js