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