JS time stamp, date to convert each other

Source: Internet
Author: User

There are many requirements for time stamping and standard time conversions in the development process, and slightly larger projects will introduce similar moment.js, but for simple H5 pages, more simple ways to process dates

/*timestr: Time, format can be: "September 16,2016 14:15:05," September 16,2016 "," 2016/09/16 14:15:05 "," 2016/09/16 "," 2014-04-23t18:55:49 ' and milliseconds DateSeparator: delimiter between year, month, and day, default to '-', TimeSeparator: delimiter between hours, minutes, seconds, default to ': '*/functiongetformatdate (Timestr, DateSeparator, TimeSeparator) {DateSeparator= DateSeparator? DateSeparator: "-"; TimeSeparator= TimeSeparator? TimeSeparator: ":"; varDate =NewDate (TIMESTR), year= Date.getfullyear (),//Get the full year (4-bit, 1970)month = Date.getmonth (),//get the month (0-11, 0 for January, remember to add 1 when using)Day = Date.getdate (),//Get Day (1-31)hour = Date.gethours (),//gets the number of hours (0-23)minute = Date.getminutes (),//gets the number of minutes (0-59)seconds = Date.getseconds (),//gets the number of seconds (0-59)Y = year +DateSeparator, M= ((month + 1) > 9? (month + 1): (' 0 ' + (month + 1)) +DateSeparator, D= (Day > 9-day: (' 0 ' + day) + ", H= (Hour > 9? Hour: (' 0 ' + hour)) +TimeSeparator, M= (Minute > 9? minute: (' 0 ' + minute)) +TimeSeparator, S= (seconds > 9? seconds: (' 0 ' +seconds)), FormatDate= Y + M + D + H + M +s; returnformatdate;}

JS time stamp, date to convert each other

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.