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

35번째 줄: 35번째 줄:
<source lang='java'>
<source 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>
==JavaScript==
[[분류: JavaScript]]
<source lang='JavaScript'>
function formatDate(date) {
var h = date.getHours()>9? date.getHours(): '0'+date.getHours();
var m = date.getMinutes()>9? date.getMinutes(): '0'+date.getMinutes();
return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+' '+h+':'+m+':'+date.getSeconds();
}
var d = new Date();
console.log(formatDate(d));
// 2014-12-14 09:03:49
</source>
</source>



2014년 12월 14일 (일) 22:54 판

  다른 뜻에 대해서는 함수 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 formatDate(date) {
	var h = date.getHours()>9? date.getHours(): '0'+date.getHours();
	var m = date.getMinutes()>9? date.getMinutes(): '0'+date.getMinutes();
	return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+' '+h+':'+m+':'+date.getSeconds();
}
var d = new Date();
console.log(formatDate(d));
// 2014-12-14 09:03:49

6 PHP

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

7 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

8 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

9 SQL

9.1 MySQL

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

9.2 Oracle

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

9.3 PostgreSQL

SELECT CURRENT_TIMESTAMP;
SELECT LOCALTIMESTAMP;

10 VBA

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

11 같이 보기