"함수 unixtime2datetime()"의 두 판 사이의 차이

58번째 줄: 58번째 줄:
var a = new Date(unixtime *1000);
var a = new Date(unixtime *1000);
var year = a.getFullYear();
var year = a.getFullYear();
var month = months[a.getMonth()];
var month = a.getMonth();
var date = a.getDate();
var date = a.getDate();
var hour = a.getHours();
var hour = a.getHours();

2015년 5월 19일 (화) 09:26 판

함수 unixtime2datetime(), unixtime to datetime
함수 timestamp2datetime(), timestamp to datetime
unix timestamp to datetime
ts2dt
ut2dt

1 Bash

date +%Y-%m-%d\ %H:%M:%S -d @1406204196
# 2014-07-24 21:16:36
unixtime=1406204196
date +"%Y-%m-%d %H:%M:%S" --date @$unixtime
# 2014-07-24 21:16:36
unixtime=1406204196
datetime=`date +"%Y-%m-%d %H:%M:%S" --date @$unixtime`
echo $datetime
# 2014-07-24 21:16:36

2 C#

string dtStr = String.Format("{0:yyyy-MM-dd HH:mm:ss}", new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(1368597301));
// 2013-05-15 05:55:01
public static String ts2dt(double ts)
{
  DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(ts).ToLocalTime();
  return String.Format("{0:yyyy-MM-dd HH:mm:ss}", dtDateTime);
}
...
Console.Write( ts2dt(1368597301) );
// 2013-05-15 14:55:01

3 Excel

=1368597301/86400+25569
// 41409.24654 ← Format Cells: General
// 2013-05-15 05:55:01 ← Format Cells: (Custom) yyyy-mm-dd hh:mm:ss
=1368597301/60/60/24+DATE(1970,1,1)

4 JavaScript

var unixtime = 1406204196;
var a = new Date(unixtime *1000);
var year = a.getFullYear();
var month = a.getMonth();
var date = a.getDate();
var hour = a.getHours();
var min = a.getMinutes();
var sec = a.getSeconds();
var datetime = year + '-' + month + '-' + date + '  ' + hour + ':' + min + ':' + sec ;

5 PHP

echo date('Y-m-d H:i:s', 1368597301);
// 2013-05-15 14:55:01
$unixtime = 1406204196;
$datetime = date('Y-m-d H:i:s', $unixtime);
echo $datetime;
// 2014-07-24 21:16:36

6 Python

import datetime
ut = 1406204196
dt = datetime.datetime.fromtimestamp( ut ).strftime('%Y-%m-%d %H:%M:%S')
print dt
# 2014-07-24 21:16:36
import time
ut = 1406204196
dt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(ut) )
print dt
# 2014-07-24 21:16:36

7 SQL

7.1 MySQL

SELECT FROM_UNIXTIME( 1368597301 );
-- 2013-05-15 14:55:01

8 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}