- //时间戳转换成日期时间2014-8-8 下午11:40:20
- function formatDate(ns){
- return new Date(parseInt(ns) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
- }
- //时间戳转换成八位日期2014-5-5
- function userDate(uData){
- var myDate = new Date(uData*1000);
- var year = myDate.getFullYear();
- var month = myDate.getMonth() + 1;
- var day = myDate.getDate();
- return year + '-' + month + '-' + day;
- }
- //时间戳转换成四位时间10:10
- function userTime(uTime){
- var myDate = new Date(uTime*1000);
- var hours = myDate.getHours();
- var minutes = myDate.getMinutes();
- return hours + ':' + minutes;
- }
- //时间戳转换成四位时间10:10:00
- function userTime(uTime){
- var myDate = new Date(uTime*1000);
- var hours = myDate.getHours();
- var minutes = myDate.getMinutes();
- var second = myDate.getSeconds();
- return hours + ':' + minutes + ':' + second;
- }
- //定时提醒设置的时间传入 (2014,05,15)返回成2014-01-21
- function setDate(year,month,day){
- return year + '-' + month + '-' + day;
- }
- //定时提醒设置的时间传入 (01:02)返回成01:01:00
- function setTime(hour,minute){
- return hour + ':' + minute+ ':00';
- }
- //时间格式2014-02-02 14:10:00改成时间戳
- function js_strto_time(str_time){
- var new_str = str_time.replace(/:/g,"-");
- new_str = new_str.replace(/ /g,"-");
- var arr = new_str.split("-");
- var datum = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3]-8,arr[4],arr[5]));
- return strtotime = datum.getTime()/1000;
- }
- //时间戳改成时间格式2014-12-12 下午01:10
- function js_date_time(unixtime){
- var timestr = new Date(parseInt(unixtime) * 1000);
- var datetime = timestr.toLocaleString().replace(/年|月/g,"-").replace(/日/g," ");
- return datetime;
- }
又有个时间格式:2014-1-1 10:10 转换成时间戳
- function js_strto_times(str_time){
- var new_str = str_time.replace(/:/g,"-");
- new_str = new_str.replace(/ /g,"-");
- var arr = new_str.split("-");
- var datum = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3]-8,arr[4]));
- return strtotime = datum.getTime()/1000;
- }