함수 now()

Jmnote (토론 | 기여)님의 2019년 11월 30일 (토) 22:47 판 (→‎R)
  다른 뜻에 대해서는 함수 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#

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

6 PHP

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

7 PowerShell

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

8 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

9 Perl

use DateTime;
print DateTime->now();
# 2018-01-17T11:17:49

10 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"

11 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

12 SQL

12.1 MySQL

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

12.2 Oracle

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

12.3 PostgreSQL

SELECT CURRENT_TIMESTAMP;
SELECT LOCALTIMESTAMP;

13 VBA

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

14 같이 보기