SoFunction
Updated on 2025-03-09

js get time and implement conversion between string and timestamp


//Get the current time:
var myDate = new Date();//Current time
var year = ();//Current year
var month = () + 1;//Current month
var day = ();//Current day
();        //Get the current year (2 digits)
();    //Get the complete year (4 digits, 1970-?????)
();       //Get the current month (0-11, 0 represents January)
();        //Get the current day (1-31)
();          //Get the current week X (0-6, 0 represents Sunday)
();         //Get the current time (the number of milliseconds starting from 1970.1.1)
();       //Get the current number of hours (0-23)
();     //Get the current number of minutes (0-59)
();     //Get the current number of seconds (0-59)
();    //Get the current number of milliseconds (0-999)
();     //Get the current date
var mytime=();     //Get the current time
( );         //Get date and time
  var oneDay = 1000 * 60 * 60 * 24;
//Get the date of the last week
  var lastDate = new Date(myDate - oneDay * 6);
  var lastYear = ();
  var lastMonth = () + 1;
  var lastDay = ();
//Get the last day of the current month
  var day = new Date(year ,month , 0);
var lastdate = ();//The last day of the current month
//Get the date of the last N months
   var lastDate = new Date(myDate - oneDay * ());
   lastDate = new Date(lastDate - N * oneDay * (() - 1));
   var lastYear = ();
   var lastMonth = () + 1;
   var lastDay = ();
//Convert string to timestamp
   var date="2014-12-06";
   date = new Date(((/-/g, "/")));
   date = ();