60
51

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【保存版】いろんな言語のyyyymmddhhmmss文字列

Last updated at Posted at 2018-06-05

※編集リクエスト超絶大歓迎

プログラミング言語編

PHP

date('YmdHis');
// Carbon版
\Carbon\Carbon::now()->format('YmdHis');

C#

DateTime.Now.ToString("yyyyMMddHHmmss");
// どんな国のサーバーでも日本時間の現在時刻を取得するなら(Azure Web Apps考慮)
DateTime.UtcNow.AddHours(9).ToString("yyyyMMddHHmmss");

Java(7以前)

new SimpleDateFormat("yyyyMMddhhmmss").format(new Date())

Java(8以降)

DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(LocalDateTime.now())

python

datetime.datetime.now().strftime('%Y%m%d%H%M%S')

javascript

//現在時刻取得(yyyymmddhhmmss)
function getCurrentTime() {
	var now = new Date();
	var res = "" + now.getFullYear() + padZero(now.getMonth() + 1) + padZero(now.getDate()) + padZero(now.getHours()) + 
		padZero(now.getMinutes()) + padZero(now.getSeconds());
	return res;
}

//先頭ゼロ付加
function padZero(num) {
    return (num < 10 ? "0" : "") + num;
}

SQL編

Oracle / PostgreSQL

TO_CHAR(CURRENT_TIMESTAMP, 'YYYYMMDDHH24MISS')

MySQL

DATE_FORMAT(NOW(), '%Y%m%d%H%i%S')

SQL Server

Format(GetDate(),'yyyyMMddHHmmss')

コマンドライン編

シェルスクリプト

date +%Y%m%d%H%M%S

コマンドプロンプト

set time_tmp=%time: =0%
set now=%date:/=%%time_tmp:~0,2%%time_tmp:~3,2%%time_tmp:~6,2%
echo %now%
60
51
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
60
51

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?