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

1번째 줄: 1번째 줄:
[[분류:Datetime]]
*example: 2011-01-01 21:00:00
*example: 2011-01-01 21:00:00


==Bash==
==Bash==
[[분류:Bash]]
<source lang='bash'>
<source lang='bash'>
NOW=`date +%Y-%m-%d\ %H:%M:%S`
NOW=`date +%Y-%m-%d\ %H:%M:%S`
7번째 줄: 9번째 줄:


==C#==
==C#==
[[분류:Csharp]]
<source lang='csharp'>
<source lang='csharp'>
String now = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
String now = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
12번째 줄: 15번째 줄:


==CMD==
==CMD==
[[분류:Cmd]]
<source lang='bash'>
<source lang='bash'>
set now=%date% %time%
set now=%date% %time%
19번째 줄: 23번째 줄:


==Java==
==Java==
[[분류:Java]]
<source lang='java'>
<source lang='java'>
Date date = new Date();
Date date = new Date();
29번째 줄: 34번째 줄:


==PHP==
==PHP==
[[분류:PHP]]
<source lang='php'>
<source lang='php'>
$now = date('Y-m-d H:i:s');
$now = date('Y-m-d H:i:s');
34번째 줄: 40번째 줄:


==Python==
==Python==
[[분류:Python]]
<source lang='Python'>
<source lang='Python'>
import time
import time
43번째 줄: 50번째 줄:


==Ruby==
==Ruby==
[[분류:Ruby]]
<source lang='Ruby'>
<source lang='Ruby'>
now = Time.now.strftime "%Y-%m-%d %H:%M:%S"
now = Time.now.strftime "%Y-%m-%d %H:%M:%S"
60번째 줄: 68번째 줄:


==SQL==
==SQL==
[[분류:SQL]]
===MySQL===
===MySQL===
[[분류:MySQL]]
<source lang='sql'>
<source lang='sql'>
select now();
select now();
69번째 줄: 79번째 줄:


===Oracle===
===Oracle===
[[분류:Oracle]]
<source lang='sql'>
<source lang='sql'>
select to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') as "Now" from dual;
select to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') as "Now" from dual;
74번째 줄: 85번째 줄:


===PostgreSQL===
===PostgreSQL===
[[분류:PostgreSQL]]
<source lang='sql'>
<source lang='sql'>
SELECT CURRENT_TIMESTAMP;
SELECT CURRENT_TIMESTAMP;
88번째 줄: 100번째 줄:
*[[timezone]]
*[[timezone]]
*[[현재]]
*[[현재]]
[[분류:Datetime]]
[[분류:Bash]]
[[분류:Csharp]]
[[분류:Cmd]]
[[분류:Java]]
[[분류:PHP]]
[[분류:Ruby]]
[[분류:SQL]]
[[분류:MySQL]]
[[분류:Oracle]]
[[분류:PostgreSQL]]

2014년 8월 25일 (월) 09:29 판

  • example: 2011-01-01 21:00:00

1 Bash

NOW=`date +%Y-%m-%d\ %H:%M:%S`

2 C#

String now = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");

3 CMD

set now=%date% %time%
echo %now%
REM 2012-08-24 15:00:22.05

4 Java

Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String now = sdf.format(date);
String now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());

5 PHP

$now = date('Y-m-d H:i:s');

6 Python

import time
t = time.time()
now = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(t))
print( now )
# 2014-08-25 00:34:40

7 Ruby

now = Time.now.strftime "%Y-%m-%d %H:%M:%S"
puts now
# 2000-03-14 01:59:00
now = Time.new
puts now
# 2000-03-14 01:59:00 +0000
now = Time.now
puts now
# 2000-03-14 01:59:00 +0000

8 SQL

8.1 MySQL

select now();
select sysdate();

8.2 Oracle

select to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') as "Now" from dual;

8.3 PostgreSQL

SELECT CURRENT_TIMESTAMP;
SELECT LOCALTIMESTAMP;

9 같이 보기