如何在旧时间戳上处理localtime()? [英] How to handle localtime() on old timestamps?

查看:81
本文介绍了如何在旧时间戳上处理localtime()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些带有旧时间戳的旧数据文件,其中

timestmap = time(NULL),其中一些可以追溯到1999年的

年。


我希望我的代码能够打印时间戳,每一个都要包含小时:分钟:从相应的旧日开始。

这项工作的唯一例程似乎是

localtime(timestmap) - 这是Windows Vista,

Visual Studio 2005 C ++。

localtime ()似乎考虑夏令时的存在

实际调用当天的时间,但它确实没有考虑夏令时的存在

为旧日。

例如,我在3-22-1999的时间戳上运行本地时间

(夏令时没有有效但是今天当Daylight

节省时间是有效的,localtime()返回小时:分钟:秒

一小时后应该如此。

这是否意味着我唯一的方法s保持过渡

所有年份的夏令时日期并且我的代码

根据过去的日期和当前的情况进行调整

天?是否有任何实用工具或更好的方法?

I have some old data files with old timestamps, where
timestmap=time(NULL), some of them date back to the
year 1999.

I want to my code to print the timestamps and each one to
include hour:minute:second as of the corresponding old day.
The only routine for this job seems to be
localtime(timestmap) - this is Windows Vista,
Visual Studio 2005 C++.
localtime() seems to consider the presence of Daylight Saving
Time for the current day when it is actually called, but it does
not seem to consider the presence of Daylight Saving Time
for the old day.
For example, I run localtime on a timestamp from 3-22-1999
(Daylight Saving Time was not effective yet) today when Daylight
Saving Time is effective and localtime() returns hour:minute:second
one hour later as it should.
Does it mean that the only way around it is to keep transition
dates for Daylight Saving Time for all years and have my code
make the adjustments depending on the old day and the current
day? Is there any utility to do that or any better way?

推荐答案

" ma **** @ hotmail.com" < ma **** @ hotmail.comwrites:
"ma****@hotmail.com" <ma****@hotmail.comwrites:

我有一些带有旧时间戳的旧数据文件,其中

timestmap = time (NULL),其中一些可以追溯到1999年的




我想用我的代码打印时间戳,每一个都打印到

包括小时:分钟:相应旧日的秒数。

此工作的唯一例程似乎是

localtime(timestmap) - 这是Windows Vista,

Visual Studio 2005 C ++。


localtime()似乎考虑夏令时的存在

时间实际调用它的当天,但确实没有考虑夏令时的存在时间为

I have some old data files with old timestamps, where
timestmap=time(NULL), some of them date back to the
year 1999.

I want to my code to print the timestamps and each one to
include hour:minute:second as of the corresponding old day.
The only routine for this job seems to be
localtime(timestmap) - this is Windows Vista,
Visual Studio 2005 C++.

localtime() seems to consider the presence of Daylight Saving
Time for the current day when it is actually called, but it does
not seem to consider the presence of Daylight Saving Time
for the old day.



[...]


听起来你的系统对localtime()的实现是错误的。

可能没有太多可以做的纠正,但是可行的解决办法是


[...]

It sounds like your system''s implementation of localtime() is buggy.
There may not be much you can do to correct it, but workarounds are
possible.


例如,我在3-22-1999的时间戳上运行本地时间

(夏令时尚未生效)今天当Daylight

节省时间有效且localtime()返回小时:分钟:秒

一小时后应该如此。


这是否意味着唯一的办法是保持过渡

所有年份的夏令时日期并且我的代码

根据过去的日期和当前的

天进行调整?有没有任何实用工具可以做到这一点或更好的方式?
For example, I run localtime on a timestamp from 3-22-1999
(Daylight Saving Time was not effective yet) today when Daylight
Saving Time is effective and localtime() returns hour:minute:second
one hour later as it should.

Does it mean that the only way around it is to keep transition
dates for Daylight Saving Time for all years and have my code
make the adjustments depending on the old day and the current
day? Is there any utility to do that or any better way?



这将是一个解决方案,但如果未来版本的

您的实现更正了localtime()中的错误,它可能会中断。 br />

替代方案可能是使用gmtime()并自行转换为本地

时间。但这需要了解时区,一年内(因为夏令时来来往往),每个地方各不相同,并且

超过历史(作为DST规则)改变,无论是在国内还是在本地)。


我认为有些时区库已经包含了大量的这些信息(< OT> Googling" tzdata可能会有所帮助< / OT>)。


这也可能是系统特定的解决方案。试试一个处理Windows和/或Visual Studio 2005 C ++的
新闻组。


-

Keith Thompson(The_Other_Keith ) ks***@mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长

That would be one solution, but it could break if a future version of
your implementation corrects the bug in localtime().

An alternative might be to use gmtime() and do the conversion to local
time yourself. But that requires knowing about the time zone, which
varies from place to place, within a year (as DST comes and goes), and
over history (as DST rules change, either nationally or locally).

I think there are time zone libraries that already include much of
this information (<OT>Googling "tzdata" may be helpful</OT>).

It''s also likely that there''s a system-specific solution. Try a
newsgroup that deals with Windows and/or with Visual Studio 2005 C++.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


ma **** @ hotmail.com 写道:

我有一些旧的数据文件使用旧的时间戳,其中一些可以追溯到1999年的

年。


localtime()似乎考虑夏令时的存在

实际调用当天的时间,但它确实没有考虑夏令时的存在时间

过去的日子。


例如,我在3-22-1999的时间戳上运行本地时间

(夏令时尚未生效)今天白天

节省时间有效,localtime()返回小时:分钟:秒

一小时后应该如此。


这是否意味着唯一的办法是保持过渡

所有年份的夏令时日期并且我的代码

根据过去的日期和当前的

天进行调整?有没有任何实用程序可以做到这一点或更好的方式?
I have some old data files with old timestamps, where
timestmap=time(NULL), some of them date back to the
year 1999.

localtime() seems to consider the presence of Daylight Saving
Time for the current day when it is actually called, but it does
not seem to consider the presence of Daylight Saving Time
for the old day.
For example, I run localtime on a timestamp from 3-22-1999
(Daylight Saving Time was not effective yet) today when Daylight
Saving Time is effective and localtime() returns hour:minute:second
one hour later as it should.
Does it mean that the only way around it is to keep transition
dates for Daylight Saving Time for all years and have my code
make the adjustments depending on the old day and the current
day? Is there any utility to do that or any better way?



检查tm_isdst的值。如果该值为正,那么DST实际上是
,如果它为零,那么DST不起作用。如果该值

为负数,则该信息不可用。除非您获得负值,否则您应该拥有正确的DST信息

,前提是您的系统具有最新的时区信息。

它可能不是你的情况,但time_t范围和精度是定义的实现和实际上不同版本的

不同版本。


你能给我一些时间戳,你得到的tm值以及你想要的tm

值吗?


-

Ioan - Ciprian Tandau

tandau _at_ freeshell _dot_ org(希望现在还不算太晚)

(......它还能运作...... )

Check the value of tm_isdst. If the value is positive then DST is
in effect, if it''s zero then DST is not in effect. If that value
is negative then that information is not available. Unless you
get a negative value you should have correct DST information
provided that your system has up to date time zone information.
It may not be your case but time_t range and precision are
implementation defined and they can actually be different between
different versions of the same compiler.

Can you give me some timestamps, the tm values you get and the tm
values you expect?

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it''s not too late)
(... and that it still works...)


文章< 11 ********************** @ y80g2000hsf.googlegroups .com> ,
ma****@hotmail.com < ma **** @ hotmail.comwrote:
In article <11**********************@y80g2000hsf.googlegroups .com>,
ma****@hotmail.com <ma****@hotmail.comwrote:

>我希望我的代码打印时间戳,每个时间点包括小时:分钟:秒相应的旧日。
这项工作的唯一例程似乎是本地时间(timestmap) - 这是Windows Vista,
Visual Studio 2005 C ++。
>I want to my code to print the timestamps and each one to
include hour:minute:second as of the corresponding old day.
The only routine for this job seems to be
localtime(timestmap) - this is Windows Vista,
Visual Studio 2005 C++.


> localtime()似乎考虑夏令时的存在
实际调用当天的时间,但它对于过去的日子,似乎没有考虑夏令时的存在。
>localtime() seems to consider the presence of Daylight Saving
Time for the current day when it is actually called, but it does
not seem to consider the presence of Daylight Saving Time
for the old day.



我最近读过(在comp.risks中我认为是)这个

是一个长期存在的Windows问题微软拒绝改变。


但是,由于这是一个系统特定的行为,我可能很容易出错(或有误解),你会需要

检查一个Windows编程新组。

-

有些想法错了,只有一个非常聪明的人
可以相信它们。 - George Orwell

I''ve recently read (in comp.risks I think it was) that this
is a long-standing Windows issue that Microsoft has refused to change.

However, as this is a system-specific behaviour and I could
easily be wrong (or have misinterpreted), you will need to
check in a Windows programming newgroup.
--
There are some ideas so wrong that only a very intelligent person
could believe in them. -- George Orwell


这篇关于如何在旧时间戳上处理localtime()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆