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

 
(사용자 3명의 중간 판 32개는 보이지 않습니다)
6번째 줄: 6번째 줄:
==Bash==
==Bash==
[[분류:Bash]]
[[분류:Bash]]
<source lang='bash'>
<syntaxhighlight lang='bash'>
NOW=`date +%Y-%m-%d\ %H:%M:%S`
now=`date +%Y-%m-%d\ %H:%M:%S`
</source>
echo $now
# 2014-09-07 08:10:26
</syntaxhighlight>


==C#==
==C#==
[[분류:Csharp]]
[[분류:Csharp]]
<source lang='csharp'>
{{참고|C샵 now}}
String now = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
<syntaxhighlight lang='csharp' run>
</source>
using System;
class Program {
    static void Main() {
        String now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        Console.WriteLine( now );
    }
}
</syntaxhighlight>


==CMD==
==CMD==
[[분류:Cmd]]
[[분류:Cmd]]
<source lang='bash'>
<syntaxhighlight lang='bash'>
set now=%date% %time%
set now=%date% %time%
echo %now%
echo %now%
REM 2012-08-24 15:00:22.05
REM 2012-08-24 15:00:22.05
</source>
</syntaxhighlight>
 
==Go==
[[분류: Go]]
{{참고|Go time.Now()}}
<syntaxhighlight lang='go' run>
package main
 
import (
    "fmt"
    "time"
)
 
func main() {
    t :=  time.Now()
    fmt.Println(t) // 2020-07-17 08:33:15.366014451 +0000 UTC m=+0.000165201
}
</syntaxhighlight>


==Java==
==Java==
[[분류:Java]]
[[분류:Java]]
<source lang='java'>
{{참고|Java now()}}
<syntaxhighlight lang='java'>
Date date = new Date();
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String now = sdf.format(date);
String now = sdf.format(date);
</source>
</syntaxhighlight>
<source lang='java'>
<syntaxhighlight lang='java'>
String now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
String now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
</source>
</syntaxhighlight>
 
==JavaScript==
[[분류: JavaScript]]
<syntaxhighlight lang='JavaScript' run>
function now() {
var date = new Date();
var m = date.getMonth()+1;
var d = date.getDate();
var h = date.getHours();
var i = date.getMinutes();
var s = date.getSeconds();
return date.getFullYear()+'-'+(m>9?m:'0'+m)+'-'+(d>9?d:'0'+d)+' '+(h>9?h:'0'+h)+':'+(i>9?i:'0'+i)+':'+(s>9?s:'0'+s);
}
console.log( now() );
</syntaxhighlight>
<syntaxhighlight lang='JavaScript' run>
function formatDate(date) {
var m = date.getMonth()+1;
var d = date.getDate();
var h = date.getHours();
var i = date.getMinutes();
var s = date.getSeconds();
return date.getFullYear()+'-'+(m>9?m:'0'+m)+'-'+(d>9?d:'0'+d)+' '+(h>9?h:'0'+h)+':'+(i>9?i:'0'+i)+':'+(s>9?s:'0'+s);
}
console.log( formatDate(new Date()) );
</syntaxhighlight>


==PHP==
==PHP==
[[분류:PHP]]
[[분류:PHP]]
<source lang='php'>
<syntaxhighlight lang='php' run>
$now = date('Y-m-d H:i:s');
$now = date('Y-m-d H:i:s');
</source>
echo $now; // 2014-09-07 08:12:08
</syntaxhighlight>
 
==PowerShell==
[[분류:PowerShell]]
<syntaxhighlight lang='PowerShell'>
$now = Get-Date -Format 'yyyy-MM-dd hh:mm:ss'
echo $now
# 2014-09-07 08:12:08
</syntaxhighlight>


==Python==
==Python==
[[분류:Python]]
[[분류:Python]]
<source lang='Python'>
{{참고|Python 현재일시 얻기}}
<syntaxhighlight lang='Python' run>
from datetime import datetime
now = datetime.today().strftime('%Y-%m-%d %H:%M:%S')
print( now ) # 2020-01-15 13:44:21
</syntaxhighlight>
<syntaxhighlight lang='Python' run>
import time
import time
t = time.time()
now = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
now = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(t))
print( now ) # 2020-01-15 13:44:21
print( now )
</syntaxhighlight>
# 2014-08-25 00:34:40
 
</source>
==Perl==
[[분류:Perl]]
<syntaxhighlight lang='perl'>
use DateTime;
print DateTime->now();
</syntaxhighlight>
 
==R==
[[분류:R]]
{{참고|R Sys.time()}}
<syntaxhighlight lang='r'>
Sys.time()
## [1] "2019-11-30 22:46:36 KST"
</syntaxhighlight>
<syntaxhighlight lang='r'>
format(Sys.time(),"%Y-%m-%d %H:%M:%S")
## [1] "2019-11-30 22:46:36"
</syntaxhighlight>


==Ruby==
==Ruby==
[[분류:Ruby]]
[[분류:Ruby]]
<source lang='Ruby'>
<syntaxhighlight lang='Ruby'>
puts Time.now.strftime "%Y-%m-%d %H:%M:%S"
puts Time.now.strftime "%Y-%m-%d %H:%M:%S"
# 2000-03-14 01:59:00
# 2000-03-14 01:59:00
puts Time.new.strftime "%Y-%m-%d %H:%M:%S"
puts Time.new.strftime "%Y-%m-%d %H:%M:%S"
# 2000-03-14 01:59:00
# 2000-03-14 01:59:00
</source>
</syntaxhighlight>
<source lang='Ruby'>
puts Time.now
# 2000-03-14 01:59:00 +0000
puts Time.new
# 2000-03-14 01:59:00 +0000
</source>


==SQL==
==SQL==
70번째 줄: 149번째 줄:
===MySQL===
===MySQL===
[[분류:MySQL]]
[[분류:MySQL]]
<source lang='sql'>
<syntaxhighlight lang='sql'>
select now();
SELECT NOW();
</source>
-- 2014-09-06 23:01:43
<source lang='sql'>
</syntaxhighlight>
select sysdate();
<syntaxhighlight lang='sql'>
</source>
SELECT SYSDATE();
-- 2014-09-06 23:01:43
</syntaxhighlight>


===Oracle===
===Oracle===
[[분류:Oracle]]
[[분류:Oracle]]
<source lang='sql'>
<syntaxhighlight 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;
</source>
</syntaxhighlight>


===PostgreSQL===
===PostgreSQL===
[[분류:PostgreSQL]]
[[분류:PostgreSQL]]
<source lang='sql'>
<syntaxhighlight lang='sql'>
SELECT CURRENT_TIMESTAMP;
SELECT CURRENT_TIMESTAMP;
</source>
</syntaxhighlight>
<source lang='sql'>
<syntaxhighlight lang='sql'>
SELECT LOCALTIMESTAMP;
SELECT LOCALTIMESTAMP;
</source>
</syntaxhighlight>
 
==VBA==
[[분류: VBA]]
<syntaxhighlight lang='vb'>
MsgBox Format(Now, "yyyy-MM-dd hh:mm:ss")
</syntaxhighlight>


==같이 보기==
==같이 보기==
97번째 줄: 184번째 줄:
*[[unixtime2datetime]]
*[[unixtime2datetime]]
*[[함수 now (unixtime)]]
*[[함수 now (unixtime)]]
*[[함수 now (iso8601)]]
*[[timezone]]
*[[timezone]]
*[[현재]]
*[[현재]]

2022년 12월 21일 (수) 14:01 기준 최신판

  다른 뜻에 대해서는 함수 now (unixtime) 문서를 참조하십시오.
  다른 뜻에 대해서는 함수 now (iso8601) 문서를 참조하십시오.
  • example: 2011-01-01 21:00:00

1 Bash[ | ]

now=`date +%Y-%m-%d\ %H:%M:%S`
echo $now
# 2014-09-07 08:10:26

2 C#[ | ]

using System;
class Program {
    static void Main() {
        String now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        Console.WriteLine( now );
    }
}

3 CMD[ | ]

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

4 Go[ | ]

package main

import (
    "fmt"
    "time"
)

func main() {
    t :=  time.Now()
    fmt.Println(t) // 2020-07-17 08:33:15.366014451 +0000 UTC m=+0.000165201
}

5 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());

6 JavaScript[ | ]

function now() {
	var date = new Date();
	var m = date.getMonth()+1;
	var d = date.getDate();
	var h = date.getHours();
	var i = date.getMinutes();
	var s = date.getSeconds();
	return date.getFullYear()+'-'+(m>9?m:'0'+m)+'-'+(d>9?d:'0'+d)+' '+(h>9?h:'0'+h)+':'+(i>9?i:'0'+i)+':'+(s>9?s:'0'+s);
}
console.log( now() );
function formatDate(date) {
	var m = date.getMonth()+1;
	var d = date.getDate();
	var h = date.getHours();
	var i = date.getMinutes();
	var s = date.getSeconds();
	return date.getFullYear()+'-'+(m>9?m:'0'+m)+'-'+(d>9?d:'0'+d)+' '+(h>9?h:'0'+h)+':'+(i>9?i:'0'+i)+':'+(s>9?s:'0'+s);
}
console.log( formatDate(new Date()) );

7 PHP[ | ]

$now = date('Y-m-d H:i:s');
echo $now; // 2014-09-07 08:12:08

8 PowerShell[ | ]

$now = Get-Date -Format 'yyyy-MM-dd hh:mm:ss'
echo $now
# 2014-09-07 08:12:08

9 Python[ | ]

from datetime import datetime
now = datetime.today().strftime('%Y-%m-%d %H:%M:%S')
print( now ) # 2020-01-15 13:44:21
import time
now = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
print( now ) # 2020-01-15 13:44:21

10 Perl[ | ]

use DateTime;
print DateTime->now();

11 R[ | ]

Sys.time()
## [1] "2019-11-30 22:46:36 KST"
format(Sys.time(),"%Y-%m-%d %H:%M:%S")
## [1] "2019-11-30 22:46:36"

12 Ruby[ | ]

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

13 SQL[ | ]

13.1 MySQL[ | ]

SELECT NOW();
-- 2014-09-06 23:01:43
SELECT SYSDATE();
-- 2014-09-06 23:01:43

13.2 Oracle[ | ]

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

13.3 PostgreSQL[ | ]

SELECT CURRENT_TIMESTAMP;
SELECT LOCALTIMESTAMP;

14 VBA[ | ]

MsgBox Format(Now, "yyyy-MM-dd hh:mm:ss")

15 같이 보기[ | ]