2
我正在嘗試製作一個易於訪問的TimeDate變量,但遇到轉換問題。在time.h中,我將如何轉換time_t的(自1/1/1970秒),到當前的本地時區(補償夏令時如果適用),使:time_t轉換格式問題
time_t Seconds;
變爲:
struct TimeDate
{
short YYYY;
unsigned char MM;
unsigned char DD;
unsigned char HH; //Non-DST, non-timezone, IE UTC (user has to add DST and TZO to get what they need)
unsigned char MM;
unsigned char S;
char TZ[4]; //This can be optionally a larger array, null terminated preferably
char TZO; //Timezone Offset from UTC
char DST; //Positive is DST (and amount of DST to apply), 0 is none, negative is unknown/error
};
在進程中不使用任何字符串文本(bar用於時區名稱)(以保持其有效性)?這也考慮到了閏年。如果TimeDate可以轉換回time_t,則爲獎勵。
嗨,pax,看當地時間,它將放入tm結構,其中是天/小時/分鐘...自1970年1月1日以來。這個問題是我不想自1970年1月1日以來經過了多少小時,我想要的是現在的時間(UTC格式,DST /時區分開)。它也不提供所用的時區或時區抵消的小時數。 – SSight3
@ SSight3:我想你想再次閱讀該說明。 – Nemo
嗨,nemo,他修改了描述,因爲我的評論,但它仍然沒有解決我的問題,這是如何將time_t轉換爲TimeDate結構,IE如何轉換成TimeDate是臭名昭着的丟失(釋義:我該如何轉換tm到TimeDate)。另請注意時區/閏年問題。 – SSight3