Help us understand the problem. What is going on with this article?

Unix-timeと日時の相互変換

More than 3 years have passed since last update.

Unixコマンドで日時の変換をする方法が、OSによって全然違うのでまとめました。

日時からUnix-timeへの変換

ローカル時刻からUnix-time

2015年12月1日(JST)をUnix-timeに変換するコマンドです。

macOS:
$ date -v15y -v12m -v1d -v0H -v0M -v0S +%s
1448895600

Linux:
$ date --date='2015-12-01 00:00:00' +%s
1448895600

Plan9:
% seconds '1 dec 2015 00:00:00'
1448895600

macOSだけ、時刻部分を省略すると現在の時刻がそのまま使われます。LinuxとPlan 9は、時刻部分が0:00:00として扱われます。

UTC表記の時刻からUnix-time

2015年12月1日(UTC)をUnix-timeに変換するコマンドです。

macOS:
$ date -u -v15y -v12m -v1d -v0H -v0M -v0S +%s
1448928000

Linux:
$ date -u --date='2015-12-01 00:00:00' +%s
1448928000

Plan9:
% seconds '1 dec 2015 00:00:00 UTC'
1448928000

Unix-timeから日時への変換

Unix-timeからローカル時刻

macOS:
$ date -r 1448895600
Tue Dec  1 00:00:00 JST 2015

Linux:
$ date -d @1448895600
Tue Dec  1 00:00:00 JST 2015

Plan9:
% date 1448895600
Tue Dec  1 00:00:00 JST 2015

Unix-timeからUTC表記の時刻

macOS:
$ date -u -r 1448895600
Mon Nov 30 15:00:00 UTC 2015

Linux:
$ date -u -d @1448895600
Mon Nov 30 15:00:00 UTC 2015

Plan9:
% date -u 1448895600
Mon Nov 30 15:00:00 GMT 2015
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした