0
0

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 1 year has passed since last update.

JST↔UTC変換

Last updated at Posted at 2020-10-29

あらすじ

UTCとJST変換ですぐ忘れていたのでメモしました。

JSTからUTCへの変換


Datetime localDt = Datetime.Now();
// {2020/10/29 14:16:19}

★UTCへ変換
localDt = localDt.ToUniversalTime();
// {2020/10/29 5:16:19}

UTCからJSTへの変換

Datetime localDt = Datetime.UtcNow();
// {2020/10/29 5:16:19}

★JSTへ変換
localDt = localDt.ToLocalTime();
// {2020/10/29 14:16:19}

#追記
特定の時間を定義したい時

Datetime now = Datetime.Now();

DateTime dt = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
// {2020/10/29 14:34:34}

DateTime wdt = new DateTime(now.Year, now.Month, now.Day, now.Hour, 0, 0);
// {2020/10/29 14:00:00}

//各プロパティ設定できる
0
0
1

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?