
var myDate = new Date();
myDategetYear(); //获取当前年份(2位)
myDategetFullYear(); //获取完整的年份(4位,1970-)
myDategetMonth(); //获取当前月份(0-11,0代表1月)
myDategetDate(); //获取当前日(1-31)
myDategetDay(); //获取当前星期X(0-6,0代表星期天)
myDategetTime(); //获取当前时间(从197011开始的毫秒数)
myDategetHours(); //获取当前小时数(0-23)
myDategetMinutes(); //获取当前分钟数(0-59)
myDategetSeconds(); //获取当前秒数(0-59)
myDategetMilliseconds(); //获取当前毫秒数(0-999)
myDatetoLocaleDateString(); //获取当前日期
var mytime=myDatetoLocaleTimeString(); //获取当前时间
myDatetoLocaleString( ); //获取日期与时间
日期时间脚本库方法列表
DateprototypeisLeapYear 判断闰年
DateprototypeFormat 日期格式化
DateprototypeDateAdd 日期计算
DateprototypeDateDiff 比较日期差
DateprototypetoString 日期转字符串
DateprototypetoArray 日期分割为数组
DateprototypeDatePart 取日期的部分信息
DateprototypeMaxDayOfDate 取日期所在月的最大天数
DateprototypeWeekNumOfYear 判断日期所在年的第几周
StringToDate 字符串转日期型
IsValidDate 验证日期有效性
CheckDateTime 完整日期时间检查
daysBetween 日期天数差
js代码:
//---------------------------------------------------
// 判断闰年
//---------------------------------------------------
DateprototypeisLeapYear = function()
{
return (0==thisgetYear()%4&&((thisgetYear()%100!=0)||(thisgetYear()%400==0)));
}
//---------------------------------------------------
// 日期格式化
// 格式 YYYY/yyyy/YY/yy 表示年份
// MM/M 月份
// W/w 星期
// dd/DD/d/D 日期
// hh/HH/h/H 时间
// mm/m 分钟
// ss/SS/s/S 秒
//---------------------------------------------------
//第一种
function getLocalTime(nS) {
return new Date(parseInt(nS) 1000)toLocaleString()replace(/:\d{1,2}$/,' ');
}
alert(getLocalTime(1293072805));
//结果是2010年12月23日 10:53//第二种
function getLocalTime(nS) {
return new Date(parseInt(nS) 1000)toLocaleString()substr(0,17)
}
alert(getLocalTime(1293072805));//第三种 格式为:2010-10-20 10:00:00
function getLocalTime(nS) {
return new Date(parseInt(nS) 1000)toLocaleString()replace(/年|月/g, "-")replace(/日/g, " ");
}
alert(getLocalTime(1177824835));
js怎么把时间戳转换为日期格式 前端有时候可能要从日期控件中拿到日期,然后参与计算,下边记录一个把日期字符串转换成时间戳的小函数。
dateStr格式为“2014-05-08 00:22:11 ”
function get_unix_time(dateStr)
{
var newstr = dateStrreplace(/-/g,'/');
var date = new Date(newstr);
var time_str = dategetTime()toString();
return time_strsubstr(0, 10);
}
js中怎么将时间戳转换为 yyyy-mm-dd格式
有三种常见方式:1、functiongetLocalTime(nS){returnnewDate(parseInt(nS)1000)toLocaleString()replace(/:\d{1,2}$/,'');}alert(getLocalTime(1293072805));结果是2010年12月23日10:532、functiongetLocalTime(nS){returnnewDate(parseInt(nS)1000)toLocaleString()substr(0,17)}alert(getLocalTime(1293072805));3、functiongetLocalTime(nS){returnnewDate(parseInt(nS)1000)toLocaleString()replace(/年|月/g,"-")replace(/日/g,"");}alert(getLocalTime(1177824835));
JS 中2015年04月07日日期格式怎么转换成时间戳格式
function get_unix_time(dateStr){ dateStr = dateStrreplace('年','-'); dateStr = dateStrreplace('月','-'); dateStr = dateStrreplace('日','-'); var newstr = dateStrreplace(/-/g,'/'); var date = new Date(newstr); var time_str = dategetTime()toString(); return time_strsubstr(0, 10);}get_unix_time("2015年04月07日");
js时间戳怎么转成日期格式
使用Date可以将毫秒时间戳转为Date对象,然后可以根据Date的方法生成需要的日期格式
如: new Date(1432269413352)
你好,很简单,直接使用Date对象就可以了。
var d = new Date(1432185095381); 如果时间戳是字符串,需要先转换一下 var timestamp = "1432185095381"; var d = new Date(+timestamp);var Y = dgetFullYear(); 2015var M = dgetMonth(); 4var day = dgetDate(); 21consolelog(({})toStringcall(d)); [object Date]
希望是你想要的答案,望采纳~~
使用Date对象可以将毫秒时间戳转为js的Date对象 然后再调用Date的getFullYear、getMonth、getDate等方法拼成想要的日期格式 var date = new Date(1433665089755);alert(dategetFullYear() + '/' + (dategetMonth() + 1) + '/' + dategetDate())
时间戳转换成日期时间2014-8-8 下午11:40:20function formatDate(ns){return new Date(parseInt(ns) 1000)toLocaleString()replace(/年|月/g, "-")replace(/日/g, " ");}时间戳转换成八位日期2014-5-5 function userDate(uData){var myDate = new Date(uData1000);var year = myDategetFullYear();var month = myDategetMonth() + 1;var day = myDategetDate();return year + '-' + month + '-' + day;}时间戳转换成四位时间10:10 function userTime(uTime){var myDate = new Date(uTime1000);var hours = myDategetHours();var minutes = myDategetMinutes();return hours + ':' + minutes;}时间戳转换成四位时间10:10:00function userTime(uTime){var myDate = new Date(uTime1000);var hours = myDategetHours();var minutes = myDategetMinutes();var second = myDategetSeconds();return hours + ':' + minutes + ':' + second;}定时提醒设置的时间传入 (2014,05,15)返回成2014-01-21function setDate(year,month,day){return year + '-' + month + '-' + day; }定时提醒设置的时间传入 (01:02)返回成01:01:00function setTime(hour,minute){return hour + ':' + minute+ ':00';}时间格式2014-02-02 14:10:00改成时间戳function js_strto_time(str_time){var new_str = str_timereplace(/:/g,"-");new_str = new_strreplace(/ /g,"-");var arr = new_strsplit("-");var datum = new Date(DateUTC(arr[0],arr[1]-1,arr[2],arr[3]-8,arr[4],arr[5]));return strtotime = datumgetTime()/1000;}时间戳改成时间格式2014-12-12 下午01:10function js_date_time(unixtime){var timestr = new Date(parseInt(unixtime) 1000);var datetime = timestrtoLocaleString()replace(/年|月/g,"-")replace(/日/g," ");return datetime;}
以上就是关于js如何获取时间全部的内容,包括:js如何获取时间、js时间戳怎么转成日期格式、js怎么把时间戳转换为日期格式等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)