C 實現時間戳與標準時間的互轉

2022-09-21 21:36:22 字數 1599 閱讀 1731

目錄

c# 時間戳與 標準時間的轉其實不難,但需要注意下,基準時間的問題。

格林威治時間起點: 1970 年 1 月 1 日的 00:00:00.000

北京時間起點:1970 年 1 月 1 日的 08:00:00.000

昨天我在這裡踩坑了,我用的是格林威治時間計算的時間戳,給計算機監控系統。計算機監控系統拿到時間戳換算後的時間總是跟我的對不上。後來發現是這個原因;

///

/// 獲取開停機的時間戳

///

///

///

public int gettimespan(datetime dtime)

///

/// 時間戳timestamp轉換成日期

///

///

///

private datetime getdatetime(int timestamp)

s**ecommand("time:" + targetdt.tostring());

return targetdt;

}這個方法將乙個 datetime 物件,獲取其值為對應於 time 的本地時間。可以看到這個方法格林威治的時間 1970-01-01 00:00:00 轉為了北京時間 1970-01-01 08iprkt:00:00

c#時間戳和格式化日期互轉

using unityengine;

using system.collections;

using system;

///

/// c#時間格式轉換為時間戳(互轉)

/// 時間戳定義為從格林威治時間 2023年01月01日00時00分00秒(北京時間2023年01月01日08時00分00秒)起至現在的總秒數。

///

public class datetime_timestamp : monobeh**iour

///

/// 時間戳timestamp轉換成日期

///

///

///

private datetime getdatetime(int timestamp)

///

/// 時間戳timestamp轉換成日期

///

///

///

private datetime getdatetime(string timestamp)

void ongui()

-> ", dtnow.tostring("yyyy-mm-dd hh:mm:ss"), m_timestamp));

} if (guilayout.button("將時間戳轉換成日期_1"))

-> ", m_timestamp, dt.tostring("yyyy-mm-dd hh:mm:ss")));

} if (guilayout.button("將時間戳轉換成日期_2"))

-> ", m_timestamp, dt.tostring("yyyy-mm-dd hh:mm:ss")));

} }

}

時間戳與標準時間的相互轉化

1.時間戳轉化為標準時間 unix時間戳 unix timestamp 或稱unix時間 unix time posix時間 posix time 是一種時間表示方式,定義為從格林威治時間1970年01月01日00時00分00秒 北京時間1970年01月01日08時00分00秒 起至現在的總秒數。但...

iOS標準時間與時間戳相互轉換

cpp view plain copy 設定時間顯示格式 nsstring timestr 2011 01 26 17 40 50 nsdateformatter formatter nsdateformatter alloc init autorelease formatter setdatest...

iOS標準時間與時間戳相互轉換

設定時間顯示格式 nsstring timestr 2011 01 26 17 40 50 nsdateformatter formatter nsdateformatter alloc init autorelease formatter setdatestyle nsdateformatterm...