473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

datetimes, tzinfo and gmtime epoch


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

y,month,d,h,m,s,wd,jd,ds = time.strptime(s1, '%d-%b-%y')
dt1 = datetime.datetime(y,month,d,h,m,s,tzinfo=Eastern)

y,month,d,h,m,s,wd,jd,ds = time.strptime(s2, '%d-%b-%y')
dt2 = datetime.datetime(y,month,d,h,m,s,tzinfo=Eastern)

print dt1, Eastern.utcoffset(dt1)
print dt2, Eastern.utcoffset(dt2)
But I'm not sure how to convert this to epoch gmtime ....

Thanks,
John Hunter

Jul 18 '05 #1
0 1487

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John Hunter | last post by:
I am using the tzinfo classes from the datetime docs, eg UTC, USTimeZone, and the instantiations Pacific, Central, Eastern, etc. I would like to take a datetime instance in the UTC timezone and...
2
by: red floyd | last post by:
Is there a portable way to convert between a struct tm and a time_t, for UTC? I know that time_t is seconds since the epoch (1970-01-01T00:00:00Z). Now, you can convert a time_t to a struct tm...
4
by: Michael Pfeifer | last post by:
Hi all, I need to convert datetimes from any timezone to UTC and back considering daylight saving. It is not enough, to just add or subtract the timezone offset. Also, I can not use c functions...
1
by: KW | last post by:
Hi all, Appreciate if someone can help me out on this. Currently, I have a tm structure holding information of the UTC time, which is very likely to be in the past, meaning not the current...
11
by: red floyd | last post by:
I have a copy of the C++ standard. Unfortunately, I don't have a copy of the C89 standard, and the question I have is related to something incorporated by reference. Specifically, what does the...
1
by: Tino Lange | last post by:
Hi! I'm surprised about the following code, maybe you can give me a hint whether that's bug or feature? I'm just trying to convert local time to GMT and one method gives a strange result: ...
3
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...
11
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...
3
by: jorba101 | last post by:
Following prototypes apply for localtime and gmtime: struct tm *localtime(const time_t *timer); struct tm *gmtime(const time_t *timer); I wonder, should I understand that localtime and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.