Javascript Date Object Application parsing

Source: Internet
Author: User
Tags local time string format

One, string to Date:
1. The string format is: yyyy-mm-dd hh24:mi:ss– using IE kernel browser must be converted to YYYY/MM/DD Hh24:mi:ss

varDatestr= "2015-04-08 14:7:12";//or 2015-4-8 14:7:12var Date = New Date(Date.Parse (datestr.Replace/-/g,'/'))); Console.Log(Date.getFullYear ()+ "-" +(Date.GetMonth ()+1)+ "-" + Date.GetDate ()+ " " + Date.GetHours ()+":"+ Date.Getminutes ()+ ":"+ Date.Getseconds ());

Running Result: 2015-4-8 14:7:12

Note:date's GetMonth (), GetDate (), getHours (), getminutes (), and getseconds () are all obtained by means of values that do not contain the prefix 0, where the getmonth () Method gets 1 fewer months than it actually is.

2. The string format is: Yyyy/mm/dd hh24:mi:ss or mm/dd/yyyy hh24:mi:ss

varDatestr= "2015/04/08 14:7:12";var Date = New Date(DATESTR); Console.Log(Date.getFullYear ()+ "-" +(Date.GetMonth ()+1)+ "-" + Date.GetDate ()+ " " + Date.GetHours ()+":"+ Date.Getminutes ()+ ":"+ Date.Getseconds ());

Running Result: 2015-4-8 14:7:12

Second, Date object method:

Method describe
Date () Returns the date and time of day.
GetDate () Returns the day of the one month (1 ~ 31) from the Date object.
GetDay () Returns the day of the week from a Date object (0 ~ 6).
GetMonth () Returns the month (0 ~ 11) from the Date object.
getFullYear () Returns the year as a four-digit number from a Date object.
GetYear () Please use the getFullYear () method instead.
GetHours () Returns the hour (0 ~ 23) of the Date object.
Getminutes () Returns the minute (0 ~ 59) of the Date object.
Getseconds () Returns the number of seconds (0 ~ 59) of the Date object.
Getmilliseconds () Returns the milliseconds (0 ~ 999) of the Date object.
GetTime () Returns the number of milliseconds since January 1, 1970.
getTimezoneOffset () Returns the minute difference between local time and Greenwich Mean Time (GMT).
getUTCDate () Returns the day of the month from the Date object according to the world (1 ~ 31).
GetUTCDay () Returns the day of the week from the Date object according to the world (0 ~ 6).
getUTCMonth () Returns the month (0 ~ 11) from the Date object according to the world.
getUTCFullYear () Returns a four-digit year from a Date object, based on the world.
getUTCHours () Returns the hour (0 ~ 23) of the Date object according to the universal.
getUTCMinutes () Returns the minute (0 ~ 59) of the Date object according to the universal.
getUTCSeconds () Returns the seconds (0 ~ 59) of a Date object according to the universal.
getUTCMilliseconds () Returns the milliseconds (0 ~ 999) of a Date object according to the universal.
Parse () Returns the number of milliseconds from midnight January 1, 1970 to the specified date (string).
SetDate (Day) Sets the day of the month in the Date object (1 ~ 31).
Setmonth (Month,day) Sets the month (0 ~ 11) in the Date object. Month is required, day is optional
setFullYear (Year,month,day) Sets the year (four digits) in the Date object. Year required, Month,day optional
Setyear () Please use the setFullYear () method instead.
Sethours (HOUR,MIN,SEC,MILLISEC) Sets the hour (0 ~ 23) in the Date object. hour required, min/sec/millisec optional
Setminutes (MIN,SEC,MILLISEC) Sets the minute (0 ~ 59) in the Date object. Min must fill, sec/millisec optional
Setseconds (SEC,MILLISEC) Sets the second (0 ~ 59) in the Date object. SEC required, millisec optional
Setmilliseconds (MILLISEC) Sets the milliseconds (0 ~ 999) in the Date object.
SetTime (MILLISEC) Sets the Date object in milliseconds.
SetUTCDate () Sets the day of the month in the Date object according to the world time (1 ~ 31).
setUTCMonth () Sets the month (0 ~ 11) in the Date object according to the world time.
setUTCFullYear () Sets the year (four digits) in the Date object according to the world time.
setUTCHours () Sets the hour in the Date object according to the world time (0 ~ 23).
setUTCMinutes () Sets the minute (0 ~ 59) in the Date object according to the world.
setUTCSeconds () Sets the seconds in the Date object according to the world time (0 ~ 59).
setUTCMilliseconds () Sets the milliseconds (0 ~ 999) in the Date object according to the world time.
Tosource () Returns the source code for the object.
ToString () Converts a Date object to a string.
toTimeString () Converts the time portion of a Date object to a string.
toDateString () Converts the date part of a Date object to a string.
toGMTString () Please use the toutcstring () method instead.
toUTCString () Converts a Date object to a string, depending on the universal.
toLocaleString () Converts a Date object to a string, based on the local time format.
toLocaleTimeString () Converts the time portion of a Date object to a string, based on the local time format.
toLocaleDateString () Converts the date part of a DateTime object to a string, based on the local time format.
UTC (YEAR,MONTH,DAY,HOURS,MINUTES,SECONDS,MS) Returns the number of milliseconds from January 1, 1970 to the specified date, depending on the time. Year is required to represent the four-digit number of years. Month is required to represent the integer of the Month (0~11). Day is required to represent the integer of the date (1 ~ 31). Hours optional, an integer representing the hour (between 0 and 23). Minutes optional, which represents the integer of the minute (0 ~ 59). Seconds optional, integer representing seconds (0 ~ a) Ms Optional, integer representing milliseconds (0 ~ 999)
ValueOf () Returns the original value of the Date object.

This address: http://blog.csdn.net/chen_zw/article/details/44497729

Javascript Date Object Application parsing

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.