함수 unixtime2datetime()

Jmnote (토론 | 기여)님의 2014년 8월 3일 (일) 20:22 판 (→‎PHP)
함수 unixtime2datetime
timestamp to datetime
unixtime 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 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

5 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

6 같이 보기

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