LoginSignup
1
1

More than 5 years have passed since last update.

JavaScript で PHP の strtotime() を実装する

Posted at
strtotime()
/**
 * 日付文字列を時刻値 (ミリ秒)に変換
 * 
 * @param  {string} d
 * @return {number}
 */
function strtotime( d ) {
  return new Date( d ).getTime();
}

使ってみる


let timeA = strtotime( "Tue Aug 08 2017 00:00:00 GMT+0900 (JST)" );
let timeB = strtotime( "Wed Aug 09 2017 00:00:00 GMT+0900 (JST)" );

console.log( timeA );
console.log( timeB );
console.log( typeof timeA );

if ( timeA > timeB )
  console.log( 'timeA is latest.' );
else
  console.log( 'timeB is latest.' );


/*
1502118000000
1502204400000
number
timeB is latest.
*/

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1