Hi friends,
I need a little help here, I 'm stuck with epoch calculation issue.
I have this datetime:
date_new = datetime(*time. strptime('20080 101T000000','%Y %m%dT%H%M%S')
[0:6])
This date_new is in UTC
Now I need to know the seconds since epoch of this new date, so I run
this:
seconds = int(time.mktime (date_new.timet uple()))
but the seconds returned belongs to :
Tue, 01 Jan 2008 03:00:00 GMT
because the localtime is in timezone 'America/Santiago': -3
I fix this trying to alter the TZ with time.tzset():
os.environ['TZ'] = 'UTC'
time.tzset()
..... and now I can gets the right epoch, but I can't restore the
previous TimeZone, I try with:
os.environ['TZ'] = '', but the time.tzset() doesn't back to the
original ( America/Santiago)
A solution should be set the os.environ['TZ'] to 'America/Santiago'
but I can't make a TZ hardcode because
the software should works on different timezones.
So the question, how can restore the system into original timezone, or
how to know the seconds since epoch
from UTC datetime without change the local system TIMEZONE.
please help 2 3517
On Thu, Aug 28, 2008 at 10:18 AM, Richard Rossel <he*******@gmai l.comwrote:
Hi friends,
I need a little help here, I 'm stuck with epoch calculation issue.
I have this datetime:
date_new = datetime(*time. strptime('20080 101T000000','%Y %m%dT%H%M%S')
[0:6])
This date_new is in UTC
Now I need to know the seconds since epoch of this new date, so I run
this:
seconds = int(time.mktime (date_new.timet uple()))
but the seconds returned belongs to :
Tue, 01 Jan 2008 03:00:00 GMT
because the localtime is in timezone 'America/Santiago': -3
I fix this trying to alter the TZ with time.tzset():
os.environ['TZ'] = 'UTC'
time.tzset()
.... and now I can gets the right epoch, but I can't restore the
previous TimeZone, I try with:
os.environ['TZ'] = '', but the time.tzset() doesn't back to the
original ( America/Santiago)
I think you need to del os.environ['TZ'] rather than setting it to the
empty string.
On my box:
Python 2.5.1 (r251:54863, Feb 4 2008, 21:48:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
>>import os, time time.asctime( )
'Thu Aug 28 11:19:57 2008'
>>#that's my correct local time time.tzname
('PST', 'PDT')
>>#that's my correct timezone os.environ['TZ'] = 'UTC' time.tzset( ) time.tzname
('UTC', 'UTC')
>>time.asctime( )
'Thu Aug 28 18:20:33 2008'
>>#we're clearly in UTC now del os.environ['TZ'] #this is the key line time.tzset( ) time.tzname
('PST', 'PDT')
>>time.asctime( )
'Thu Aug 28 11:21:05 2008'
>>#and now we're back to my original timezone
Regards,
Chris
========
Follow the path of the Iguana...
Rebertia: http://rebertia.com
Blog: http://blog.rebertia.com
>
A solution should be set the os.environ['TZ'] to 'America/Santiago'
but I can't make a TZ hardcode because
the software should works on different timezones.
So the question, how can restore the system into original timezone, or
how to know the seconds since epoch
from UTC datetime without change the local system TIMEZONE.
please help
-- http://mail.python.org/mailman/listinfo/python-list
On 28 ago, 14:25, "Chris Rebert" <cvrebert+...@g mail.comwrote:
On Thu, Aug 28, 2008 at 10:18 AM, Richard Rossel <henhis...@gmai l.comwrote:
Hi friends,
I need a little help here, I 'm stuck with epoch calculation issue.
I have this datetime:
date_new = datetime(*time. strptime('20080 101T000000','%Y %m%dT%H%M%S')
[0:6])
This date_new is in UTC
Now I need to know the seconds since epoch of this new date, so I run
this:
seconds = int(time.mktime (date_new.timet uple()))
but the seconds returned belongs to :
Tue, 01 Jan 2008 03:00:00 GMT
because the *localtime is in timezone 'America/Santiago': -3
I fix this trying to alter the TZ with time.tzset():
*os.environ['TZ'] = 'UTC'
time.tzset()
.... and now I can gets the right epoch, but I can't restore the
previous TimeZone, I try with:
os.environ['TZ'] = '', but the time.tzset() doesn't back to the
original ( America/Santiago)
I think you need to del os.environ['TZ'] rather than setting it to the
empty string.
On my box:
Python 2.5.1 (r251:54863, Feb *4 2008, 21:48:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin>>import os, time
>time.asctime ()
'Thu Aug 28 11:19:57 2008'>>#that's my correct local time
>time.tzname
('PST', 'PDT')
>#that's my correct timezone os.environ['TZ'] = 'UTC' time.tzset() time.tzname
('UTC', 'UTC')
>time.asctime ()
'Thu Aug 28 18:20:33 2008'>>#we're clearly in UTC now
>del os.environ['TZ'] #this is the key line time.tzset() time.tzname
('PST', 'PDT')
>time.asctime ()
'Thu Aug 28 11:21:05 2008'
>#and now we're back to my original timezone
Thanks Chris, and also I found that with reload(time) works too
--
Richard Rossel
Ing. Civil Informatico
Valparaiso, Chile This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John Hunter |
last post by:
I have a python2.3 datetime instance and a tzinfo instance (eg Eastern
from the python library reference).
What is the best way to convert that datetime instance to seconds
since the epoch, gmtime?
s1 = '2-Apr-04' # before dst
s2 = '5-Apr-04' # after dst
|
by: Sunil |
last post by:
Can someone suggest me how do i write a code in VB for
epoch time. I want if the value is entered it changes into
time and if time is enetred i get the value
|
by: eight02645999 |
last post by:
hi
how can i get the number of days since epoch using the time module?
or do i have to manually do the arithmetic?
thanks
|
by: Summu82 |
last post by:
HI I have to convert a time in the format
i have
year
month
day
hour
min and seconds
I need to convert this into time in seconds since 1 jan 1970 i.e the
|
by: Extremest |
last post by:
I have a bunch of dates in a couple different formats. I would like to
convert them to epoch. The dates are like this
Mon, 12 Jun 2006 09:18:22 GMT
12 Jun 2006 10:37:28 GMT
I can do this in perl easily with the Date::Manip module but don't know
how to do it in c#. Is there a way to do this or do I need to right
something to parse each date?
| |
by: Mark |
last post by:
I want to simply get the unix style epoch time
(number of secs to now from Jan 01, 1970 UTC) for
use as a timestamp to track the staleness of some
objects. So I don't care about time zones or whatever
as long as it's consistent. So I picked the epoch time
UTC getting the value I wanted, "timestamp", this way:
#include "boost/date_time/local_time/local_time.hpp"
using namespace boost::gregorian;
using namespace boost::local_time;
|
by: Grey Alien |
last post by:
I need to convert timestamps that are given as the number of seconds
that have elapsed since midnight UTC of January 1, 1970, (not counting
leap seconds).
It seems all of the std C functions expect positive offsets from this
date and are incapable of working on dates preceeding the epoch (i.e.
negative offsets) - which IMHO shows a remarkable lack of foresight -
and is *just* a little bit annoying.
Does anyone know of an algo I can...
|
by: usenet |
last post by:
Is the epoch time the number of seconds elapsed since January 1st 1970
in my timezone or as per UTC? I mean, if A's program makes a call to
time() in Melboune and B's program makes a call to time() in Montreal
AT THIS VERY INSTANT, will they return the same values, or will A's
program return a value that is more than B's value by 36000 (since
Melboune is 10 hours ahead of Montreal).
Thanks,
Anil
|
by: pavanponnapalli |
last post by:
hi,
i am using Date::Time and using localtime function to convert a given timestamp to epoch seconds. Everything is fine. The problem comes when we give date someting like 2008-11-31 04:45:45 . The error it is giving is date out of range (0..30). It is not converting date with 31 to its equvivalent epoch seconds.
How to convert this into epoch seconds? Pls give me a solution.
Thanks,
Pavan
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |