我需要jquery / javascript代码来转换日期格式而不使用exteranl js库。以下是示例
我需要从FORMAT 1转换为FORMAT 2
FORMAT 1: Wed Apr 20 07:05:00 PDT 2016
FORMAT 2: 2016-04-20 07:23:42.476
答案 0 :(得分:0)
尝试:
var todayDate=new Date("Wed Apr 20 07:05:00 PDT 2016 ");
var format ="AM";
var hour=todayDate.getHours();
var min=todayDate.getMinutes();
var sec = todayDate.getSeconds();
if(hour>11){format="PM";}
if (hour > 12) { hour = hour - 12; }
if (hour == 0) { hour = 12; }
if (min < 10){min = "0" + min;}
document.write(todayDate.getFullYear() + "-" +(todayDate.getMonth()+1) + "-" + todayDate.getDate() + " " + hour+":"+min+":"+sec+" "+format);