JS time formatting appears 2015-02-07 hh:12:30

Source: Internet
Author: User
Tags date1

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.