함수 now()

(Now에서 넘어옴)
  다른 뜻에 대해서는 함수 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();
# 2018-01-17T11:17:49

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 같이 보기[ | ]