Conversion between JS timestamp and time format

Source: Internet
Author: User

//Timestamp converted to datetime 2014-8-8 PM 11:40:20functionFormatDate (NS) {return NewDate (parseint (NS) *). toLocaleString (). Replace (/year | month/g, "-"). Replace (/day/g, "");}//Timestamp converted to eight-bit date 2014-5-5functionuserdate (uData) {varMyDate =NewDate (udata*1000); varYear =mydate.getfullyear (); varmonth = Mydate.getmonth () + 1; varDay =mydate.getdate (); returnYear + '-' + month + '-' +Day ;}//Timestamp converted to four-bit time 10:10functionUsertime (utime) {varMyDate =NewDate (utime*1000); varHours =mydate.gethours (); varminutes =mydate.getminutes (); returnHours + ': ' +minutes;}//Timestamp converted to four-bit time 10:10:00functionUsertime (utime) {varMyDate =NewDate (utime*1000); varHours =mydate.gethours (); varminutes =mydate.getminutes (); varSecond =mydate.getseconds (); returnHours + ': ' + minutes + ': ' +second;}//timed Reminder Set time incoming (2014,05,15) returned to 2014-01-21functionsetDate (year,month,day) {returnYear + '-' + month + '-' +Day ;}//timed Reminder Set time incoming (01:02) return to 01:01:00functionsettime (hour,minute) {returnHour + ': ' + minute+ ': 00 ';}//time format 2014-02-02 14:10:00 change to timestampfunctionJs_strto_time (str_time) {varNew_str = Str_time.replace (/:/g, "-"); New_str= New_str.replace (//g, "-");vararr = New_str.split ("-"); varDatum =NewDate (DATE.UTC (arr[0],arr[1]-1,arr[2],arr[3]-8,arr[4],arr[5])); returnStrtotime = Datum.gettime ()/1000;}//Timestamp changed to time format 2014-12-12 pm 01:10functionJs_date_time (unixtime) {varTimestr =NewDate (parseint (unixtime) * 1000); vardatetime = Timestr.tolocalestring (). Replace (/year | month/g, "-"). Replace (/day/g, "" "); returndatetime;}

Conversion between JS timestamp and time format

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.