A daily summary of javascript Learning (Date objects)

  • 2020-10-23 20:53:22
  • OfStack

1, Date. now ()


 //Date.now() is in ECMAScript 5
    //Prior to that, use +new Date()
    // Get current time 
    var now = (typeof Date.now == "function" ? Date.now() : +new Date());
    alert("Right now: " + now);

2. Date.parse() method


var now = new Date();
  alert(now);
  
  var someDate = new Date(Date.parse("May 25, 2004"));
  //parse()  Method resolvable 1 Date time string, and return  1970/1/1  The number of milliseconds between midnight and the time of the date. 
  alert(someDate);

3. Date UTC() and toUTCString() methods


//UTC()  Method returns based on universal time  1970  years  1  month  1  day   The number of milliseconds to the specified date. 
  //Date.UTC(year,month,day,hours,minutes,seconds,ms)
  /*
   year  A necessity. Year denoting 4 Digit number. 
   month  A necessity. Represents an integer of the month, between  0 ~ 11 . 
   day  A necessity. An integer representing a date, between  1 ~ 31 . 
   hours  Optional. An integer representing hours, between  0 ~ 23 . 
   minutes  Optional. An integer representing minutes, between  0 ~ 59 . 
   seconds  Optional. An integer representing seconds, between  0 ~ 59 . 
   ms  Optional. An integer representing milliseconds, between  0 ~ 999 . 
   Date.UTC()  is 1 A static method, because constructors are required  Date()  To call it instead of going through one  Date  Object invocation. 
   Date.UTC()  Method to specify a date and time, both of which are  UTC  Time, in  GMT  Time zone. The specified  UTC  The time will be converted to milliseconds, 
    Construct the function like this  Date()  And methods  Date.setTime()  You can use it. 
  */
  
  //toUTCString()  The method can be based on universal time  (UTC)  the  Date  Converts the object to a string and returns the result. 
  
  //January 1, 2000 at midnight
  var y2k = new Date(Date.UTC(2000, 0));
  alert(y2k.toUTCString());
  
  //May 5, 2005 at 5:55:55 PM GMT
  var allFives = new Date(Date.UTC(2005, 4, 5, 17, 55, 55));
  alert(allFives.toUTCString());

The above is the summary of today's javascript study, which will continue to be updated every day. I hope you will continue to pay attention to it.


Related articles: