Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

timezone conversion

timezone conversion

timezone conversion

does anyone understand the timezone conversions?
I found I cannot see the "real" timestamps of the files in a share in Asia when I mount it to my server in Pacific NW.
I thought I can do the following and it will give me the results I want but it did not.

CODE -->

time_today_KL = datetime.combine(date.today(), time(), tzinfo=timezone("Asia/Kuala_Lumpur")) # Time now in Kuala_Lumpur
t_start_KL = time_today_KL - timedelta(hours=24 # Start time 
t_end_KL = t_start_KL + timedelta(hours=24)     # End time

t_start_KL = t_start_KL.timestamp()
t_end_KL = t_end_KL.timestamp()

print(f" Start time={t_start_KL}, End time={t_end_KL}")

for file in folder.iterdir():
    mtime = file.stat().st_mtime
    if t_start_KL  <= mtime < t_end_KL :
        print(file.name, mtime, datetime.fromtimestamp(mtime)) 
thank you.

RE: timezone conversion

Hi Tester_V,

I tried getting times as in your example, but it does not work for me. I have Python version 3.8.10. What Python version you have?

So i have done it at different way


from datetime import datetime, timedelta
import pytz

time_now = datetime.now()

current_timezone = pytz.timezone("Europe/Amsterdam")
timezone_KL = pytz.timezone("Asia/Kuala_Lumpur")

time_now_KL = time_now.astimezone(timezone_KL)

t_start_KL = time_now_KL - timedelta(hours=24)
t_end_KL = t_start_KL + timedelta(hours=24)

print("Time Now Here:")

print("Time Now in Kuala Lumpur:")

print("Start Time:")

print("End Time:")


$ python3 timezone_example.py
Time Now Here:
2023-07-01 00:43:40.814256

Time Now in Kuala Lumpur:
2023-07-01 06:43:40.814256+08:00

Start Time:
2023-06-30 06:43:40.814256+08:00
End Time:
2023-07-01 06:43:40.814256+08:00 

It seems to compute the times correctly.
Where is exactly your problem ?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close