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

 
(사용자 2명의 중간 판 19개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[분류: 타임스탬프]]
[[분류: 변환]]
[[분류: 변환]]
;함수 unixtime2datetime
;함수 unixtime2datetime(), unixtime to datetime
;timestamp to datetime
;함수 timestamp2datetime(), timestamp to datetime
;unixtime to datetime
;unix timestamp to datetime
;unix timestamp to datetime
;ts2dt
;ts2dt
9번째 줄: 9번째 줄:
==Bash==
==Bash==
[[category: Bash]]
[[category: Bash]]
<source lang='bash'>
<syntaxhighlight lang='bash'>
date +%Y-%m-%d\ %H:%M:%S -d @1406204196
date +%Y-%m-%d\ %H:%M:%S -d @1406204196
# 2014-07-24 21:16:36
# 2014-07-24 21:16:36
</source>
</syntaxhighlight>
<source lang='bash'>
<syntaxhighlight lang='bash'>
unixtime=1406204196
unixtime=1406204196
date +"%Y-%m-%d %H:%M:%S" --date @$unixtime
date +"%Y-%m-%d %H:%M:%S" --date @$unixtime
# 2014-07-24 21:16:36
# 2014-07-24 21:16:36
</source>
</syntaxhighlight>
<source lang='bash'>
<syntaxhighlight lang='bash'>
unixtime=1406204196
unixtime=1406204196
datetime=`date +"%Y-%m-%d %H:%M:%S" --date @$unixtime`
datetime=`date +"%Y-%m-%d %H:%M:%S" --date @$unixtime`
echo $datetime
echo $datetime
# 2014-07-24 21:16:36
# 2014-07-24 21:16:36
</source>
</syntaxhighlight>


==C#==
==C#==
[[category: csharp]]
[[category: csharp]]
<source lang='csharp'>
<syntaxhighlight lang='csharp'>
string dtStr = String.Format("{0:yyyy-MM-dd HH:mm:ss}", new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(1368597301));
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
// 2013-05-15 05:55:01
</source>
</syntaxhighlight>
<source lang='csharp'>
<syntaxhighlight lang='csharp'>
public static String ts2dt(double ts)
public static String ts2dt(double ts)
{
{
38번째 줄: 38번째 줄:
}
}
...
...
Console.Write(ts2dt(1368597301));
Console.Write( ts2dt(1368597301) );
// 2013-05-15 14:55:01
// 2013-05-15 14:55:01
</source>
</syntaxhighlight>
 


==Excel==
==Excel==
[[category: excel]]
[[category: excel]]
<source lang='php'>
<syntaxhighlight lang='php'>
=1368597301/86400+25569
=1368597301/86400+25569
// 41409.24654 ← Format Cells: General
// 41409.24654 ← Format Cells: General
// 2013-05-15 05:55:01 ← Format Cells: (Custom) yyyy-mm-dd hh:mm:ss
// 2013-05-15 05:55:01 ← Format Cells: (Custom) yyyy-mm-dd hh:mm:ss
</source>
</syntaxhighlight>
<source lang='php'>
<syntaxhighlight lang='php'>
=1368597301/60/60/24+DATE(1970,1,1)
=1368597301/60/60/24+DATE(1970,1,1)
</source>
</syntaxhighlight>
 
==JavaScript==
[[category: JavaScript]]
<syntaxhighlight lang='JavaScript'>
var unixtime = 1406204196;
var datetime = new Date(unixtime*1000).toISOString().substring(0,19).replace(/T/,' ');
</syntaxhighlight>
<syntaxhighlight lang='JavaScript'>
var unixtime = 1406204196;
var d = new Date(unixtime *1000);
var datetime = d.getFullYear()+"-"+("0"+(d.getMonth()+1)).slice(-2)+"-"+("0"+d.getDate()).slice(-2)+" "
  +("0"+d.getHours()).slice(-2)+":"+("0"+d.getMinutes()).slice(-2)+":"+("0"+d.getSeconds()).slice(-2);
</syntaxhighlight>


==PHP==
==PHP==
[[category: PHP]]
[[category: PHP]]
<source lang='PHP'>
<syntaxhighlight lang='php'>
echo date('Y-m-d H:i:s', 1368597301);
// 2013-05-15 14:55:01
</syntaxhighlight>
<syntaxhighlight lang='PHP'>
$unixtime = 1406204196;
$unixtime = 1406204196;
$datetime = date('Y-m-d H:i:s', $unixtime);
$datetime = date('Y-m-d H:i:s', $unixtime);
echo $datetime;
echo $datetime;
// 2014-07-24 21:16:36
// 2014-07-24 21:16:36
</source>
</syntaxhighlight>


==Python==
==Python==
[[category: Python]]
[[category: Python]]
<source lang='Python'>
{{참고|파이썬 timestamp를 datetime으로 변환}}
<syntaxhighlight lang='Python' run>
import datetime
import datetime
ut = 1406204196
ut = 1406204196
dt = datetime.datetime.fromtimestamp( ut ).strftime('%Y-%m-%d %H:%M:%S')
dt = datetime.datetime.fromtimestamp( ut ).strftime('%Y-%m-%d %H:%M:%S')
print dt
print( dt ) # 2014-07-24 21:16:36
# 2014-07-24 21:16:36
</syntaxhighlight>
</source>
<syntaxhighlight lang='Python' run>
<source lang='Python'>
import time
import time
ut = 1406204196
ut = 1406204196
dt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(ut) )
dt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(ut) )
print dt
print( dt ) # 2014-07-24 21:16:36
# 2014-07-24 21:16:36
</syntaxhighlight>
</source>
 
==SQL==
[[category: SQL]]
===MySQL===
[[category: MySQL]]
<syntaxhighlight lang='mysql'>
SELECT FROM_UNIXTIME( 1368597301 );
# 2013-05-15 14:55:01
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[함수 datetime2unixtime]]
*[[함수 datetime2unixtime()]]
*[[함수 now()]]
*[[Bash Unixtime-DATETIME 변환]]
*[[Bash Unixtime-DATETIME 변환]]
*[[unixtime]]
*[[unixtime]]
*[[datetime]]
*[[datetime]]

2021년 10월 9일 (토) 13:25 기준 최신판

함수 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 datetime = new Date(unixtime*1000).toISOString().substring(0,19).replace(/T/,' ');
var unixtime = 1406204196;
var d = new Date(unixtime *1000);
var datetime = d.getFullYear()+"-"+("0"+(d.getMonth()+1)).slice(-2)+"-"+("0"+d.getDate()).slice(-2)+" "
  +("0"+d.getHours()).slice(-2)+":"+("0"+d.getMinutes()).slice(-2)+":"+("0"+d.getSeconds()).slice(-2);

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