1. Background of the problem
Recently, in the process of doing the project, encountered a problem: the use of JS to format the date time, the page appears 2015-02-07 hh:12:30, the hour does not show the data; where HH is changed to hh, sometimes the hour display HH
var daytime = $ ("#endTime"). Val (); var dtime = new Date (daytime);d Time.settime (Dtime.gettime () +365*100); var date = new Dat E (Dtime.gettime ()); $ ("#endDate"). Val (Date.fromat ("Yyyy-mm-dd hh:mm:ss"));
2, problem analysis
(1) For the format time, wherein the format is: Yyyy-mm-dd hh:mm:ss,hh is displayed 12 hours, if it is two o'clock in the afternoon, will show 02; The item appears in six o'clock in the morning, such as:
HH:00:40 is displayed directly in the display box, possibly because the format is incompatible
(2) Format: Yyyy-mm-dd HH:mm:ss, sometimes 2015-02-07 hh:12:30 situation will appear
3, the Problem method
Use conventional methods to stitch the date and time directly
var daytime = $ ("#endTime"). Val (); var dtime = new Date (daytime);d Time.settime (Dtime.gettime () +365*100); var date = new Dat E (Dtime.gettime ()); var year = Date.getfullyear (), var month = Date.getmonth () +1;var day = Date.getdate (); var hour = date.ge Thours (); var minute = Date.getminutes (); var second = Date.getseconds (); var date1 = year+ "-" + (month<10? ") 0 "+month:month" + "-" + (day<10?) 0 "+day:day" + "+" + (hour<10? ") 0 "+hour:hour" + ":" + (minute<10? ") 0 "+minute:minute" + ":" + (second<10? ") 0 "+second:second); $ (" #endDate "). Val (date1);
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
JS time formatting appears 2015-02-07 hh:12:30