Dunno off the top of my head, but a quick search finds..
How do I print a Python datetime in the local timezone?
21 Replies - 33330 Views - Last Post: 20 December 2015 - 03:44 PM
#17
Re: I get a "TypeError: must be str,not tuple"
Posted 20 December 2015 - 04:26 AM
Iv read that page .. but not sure though how im going to apply it in my case. I have a list with many rows of datetime objects, which I want to convert to local timezone.
Feels like there is many commands/libraries for this issue , which makes me kinda confused.
Feels like there is many commands/libraries for this issue , which makes me kinda confused.
#18
Re: I get a "TypeError: must be str,not tuple"
Posted 20 December 2015 - 04:52 AM
Forgot to mention: The current timezones are in UTC, but i want to convert them into local timezone.
#19
Re: I get a "TypeError: must be str,not tuple"
Posted 20 December 2015 - 04:53 AM
Explore. Experiment. In particular, if you are not following a structured tutorial, then this is what you need to do.
#20
Re: I get a "TypeError: must be str,not tuple"
Posted 20 December 2015 - 05:05 AM
Yea will try do so .. but kinda hard with python , since there is not so much material out there compared to bigger programming languages.
#21
Re: I get a "TypeError: must be str,not tuple"
Posted 20 December 2015 - 05:39 AM
I disagree. But this is the path you've chosen by not undertaking formal, structured, learning with a book or sequence of tutorials. You've effectively said "I don't need a book, I can work it out myself".
(I presume this because you did not respond when I asked which tutorial you were following, and because of the significant gaps in your knowledge. E.g. string concatenation.)
I'll drop out now. Maybe someone else will assist you. Good luck.
(I presume this because you did not respond when I asked which tutorial you were following, and because of the significant gaps in your knowledge. E.g. string concatenation.)
I'll drop out now. Maybe someone else will assist you. Good luck.
This post has been edited by andrewsw: 20 December 2015 - 05:40 AM
#22
Re: I get a "TypeError: must be str,not tuple"
Posted 20 December 2015 - 03:44 PM
Ok andrew no problem ;P
Anyone who could help me out?
I'v played around with some codes now on converting strings to local timezone from utc.
For example:
But Im not really sure on how to do the same for my list containing sevral rows with datetime objects?
In this case it is the newList I would like to convert into local timezone:
Anyone who could help me out?
I'v played around with some codes now on converting strings to local timezone from utc.
For example:
now_utc=datetime.utcnow()
local_tz = pytz.timezone('Europe/Stockholm')
now_utc = pytz.utc.localize(now_utc)
local_time = now_utc.astimezone(local_tz)
But Im not really sure on how to do the same for my list containing sevral rows with datetime objects?
In this case it is the newList I would like to convert into local timezone:
file=open("datafile.txt","r")
newList=[]
for line in file:
frmt = '%Y-%m-%d %H:%M:%S.%f'
a,b,c=line.split()
newList.append(datetime.datetime.strptime(a + " " +b, frmt))

New Topic/Question
Reply



MultiQuote

|