function getLocalTime(nS) { var date = new Date(nS); Y = date.getFullYear() + '年'; M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '月'; D = date.getDate() + '日 '; h = date.getHours() + ':'; m = date.g…
1.时间戳转换为标准日期时间格式: function timeFormat(dateStr) { var date = new Date(dateStr); Y = date.getFullYear() + '-'; M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'; D = date.getDate() + ' '; h = (date.getHours() < 10 ? '0'…
简介:字符串转日期型函数 传入一个字符串格式的日期,如何转换为日期型的.以下为转换方案. //字符串转换为日期函数,返回日期型(传入的日期格式2014-04-22) function StringToDate(str) { var strDate = str.split(" "); var strDatepart = strDate[0].split("-"); var dtDate = new Date(strDatepart[0],strDatepart[…
/*将JSON Date 格式转换为JavaScript 的Date 类型JSON Date 格式:"/Date(146471041000)/"*/function JSONDateToJSDate(jsondate) { if (jsondate != "" && jsondate != null) { var date = new Date(parseInt(jsondate.replace("/Date(", "&…
function datetime_to_unix(datetime){ var tmp_datetime = datetime.replace(/:/g,'-'); tmp_datetime = tmp_datetime.replace(/ /g,'-'); var arr = tmp_datetime.split("-"); var now = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3]-8,arr…
1. 将时间戳转换成日期格式: function timestampToTime(timestamp) { var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000 var Y = date.getFullYear() + '-'; var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'; var D…
function (data) { var date = new Date(data) var Y = date.getFullYear() + '-' var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-' var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ' var…
最近项目需要在前端将一个13位的时间戳显示成日期格式,在网上查了很多都不符合要求,只有一个是能满足要求的,在这记录一下,说不定以后还用的着. 13位时间戳改为yyyy-MM-dd HH-mm-ss 格式 目标时间戳:1516324500000 //将时间戳改为yyyy-MM-dd HH-mm-ss function formatDateTime(unix) { var now = new Date(parseInt(unix) * 1); now = now.toLocaleString().r…
//时间戳转换 function add0(m){return m<10?'0'+m:m } function formatDate(timestamp) { //timestamp是整数,否则要parseInt转换 var time = new Date(timestamp); var y = time.getFullYear(); var m = time.getMonth()+1; var d = time.getDate(); var h = time.getHours(); var m…
{ field: 'createdTime', title: '创建时间', formatter: function (value, row, index) { return changeDateFormat(value) } }, function changeDateFormat(cellval) { var dateVal = cellval + ""; if (cellval != null) { var date = new Date(parseInt(dateVal.rep…