LoginSignup
14
14

More than 5 years have passed since last update.

javascript UNIXタイムから、Y-m-d形式に変換する関数

Last updated at Posted at 2017-02-15
function unixTime2ymd(intTime){
    // var d = new Date( intTime );
↓↓↓↓↓↓↓ あなたの記事の内容
    var d = new Date( intTime );
    var year  = d.getFullYear();
───────
    var d = new Date( intTime );
    var y = new Date( intTime * 1000 );
    var year  = y.getFullYear();
↑↑↑↑↑↑↑ 編集リクエストの内容
    var month = d.getMonth() + 1;
    var day  = d.getDate();
    var hour = ( '0' + d.getHours() ).slice(-2);
    var min  = ( '0' + d.getMinutes() ).slice(-2);
    var sec   = ( '0' + d.getSeconds() ).slice(-2);

    return( year + '-' + month + '-' + day + ' ' + hour + ':' + min + ':' + sec );

}
14
14
5

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
14
14