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

 
(사용자 2명의 중간 판 12개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[분류: 타임스탬프]]
[[분류: 변환]]
[[분류: 변환]]
;함수 datetime2unixtime()
;함수 datetime2unixtime()
5번째 줄: 6번째 줄:
==Bash==
==Bash==
[[category: Bash]]
[[category: Bash]]
<source lang='bash'>
<syntaxhighlight lang='bash'>
echo "2014-07-24 21:16:36" | date +%s
# 1406204196
</syntaxhighlight>
<syntaxhighlight lang='bash'>
datetime="2014-07-24 21:16:36"
datetime="2014-07-24 21:16:36"
date +%s --date "$datetime"
date +%s --date "$datetime"
# 1406204196
# 1406204196
</source>
</syntaxhighlight>
<source lang='bash'>
<syntaxhighlight lang='bash'>
datetime="2014-07-24 21:16:36"
datetime="2014-07-24 21:16:36"
unixtime=`date +%s --date "$datetime"`
unixtime=`date +%s --date "$datetime"`
echo $unixtime
echo $unixtime
# 1406204196
# 1406204196
</source>
</syntaxhighlight>


==Excel==
==Excel==
[[category: Excel]]
[[category: Excel]]
<source lang='php'>
<syntaxhighlight lang='php'>
// A1 = 2013-05-15  5:55:01 AM
// A1 = 2013-05-15  5:55:01 AM
=(A1-DATE(1970,1,1))*86400
=(A1-DATE(1970,1,1))*86400
// 1368597301
// 1368597301
</source>
</syntaxhighlight>
 
==Go==
[[분류: Go]]
<syntaxhighlight lang='go' run>
package main
 
import (
"fmt"
"time"
)
 
func main() {
t, _ := time.Parse(time.RFC3339, "2014-07-24T21:16:36Z")
fmt.Println(t.Unix()) // 1406236596 (UTC)
}
</syntaxhighlight>


==JavaScript==
==JavaScript==
[[category: JavaScript]]
[[category: JavaScript]]
<source lang='JavaScript'>
<syntaxhighlight lang='JavaScript' run>
var date = "2014-07-24 21:16:36";
var date = "2014-07-24 21:16:36";
console.log(new Date(date).getTime());
console.log( new Date(date).getTime() ); // 1406204196000 (in KST)
// 1406204196000
</syntaxhighlight>
</source>


==PHP==
==PHP==
[[category: PHP]]
[[category: PHP]]
<source lang='PHP'>
<syntaxhighlight lang='PHP' run>
$datetime = "2014-07-24 21:16:36";
$datetime = "2014-07-24 21:16:36";
$unixtime = date('U', strtotime($datetime));
$unixtime = date('U', strtotime($datetime));
echo $unixtime;
echo $unixtime; // 1406236596 (UTC)
// 1406204196
</syntaxhighlight>
</source>


==Python==
==Python==
[[category: Python]]
[[category: Python]]
<source lang='Python'>
<syntaxhighlight lang='Python'>
import time
import time
dt = "2014-07-24 21:16:36"
dt = "2014-07-24 21:16:36"
50번째 줄: 69번째 줄:
print ut
print ut
# 1406204196.0
# 1406204196.0
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2023년 2월 25일 (토) 19:03 기준 최신판

함수 datetime2unixtime()
함수 datetime2timestamp()

1 Bash[ | ]

echo "2014-07-24 21:16:36" | date +%s
# 1406204196
datetime="2014-07-24 21:16:36"
date +%s --date "$datetime"
# 1406204196
datetime="2014-07-24 21:16:36"
unixtime=`date +%s --date "$datetime"`
echo $unixtime
# 1406204196

2 Excel[ | ]

// A1 = 2013-05-15  5:55:01 AM
=(A1-DATE(1970,1,1))*86400
// 1368597301

3 Go[ | ]

package main

import (
	"fmt"
	"time"
)

func main() {
	t, _ := time.Parse(time.RFC3339, "2014-07-24T21:16:36Z")
	fmt.Println(t.Unix()) // 1406236596 (UTC)
}

4 JavaScript[ | ]

var date = "2014-07-24 21:16:36";
console.log( new Date(date).getTime() ); // 1406204196000 (in KST)

5 PHP[ | ]

$datetime = "2014-07-24 21:16:36";
$unixtime = date('U', strtotime($datetime));
echo $unixtime; // 1406236596 (UTC)

6 Python[ | ]

import time
dt = "2014-07-24 21:16:36"
ut = time.mktime(time.strptime(dt, "%Y-%m-%d %H:%M:%S"))
print ut
# 1406204196.0

7 같이 보기[ | ]

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