Python Forum
Timestamp of file changes if a share mapped to a server….
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Timestamp of file changes if a share mapped to a server….
#27
(Jul-02-2023, 05:00 AM)tester_V Wrote: Why I'm failing, I'm comparing the same time format that is UTC....

Sorry about this, I did not mean to give you a hard time!
Thank you.
I think deanhystad has explain this in servals ways.

To take a little more about this,so pytz as used in this Thread is deprecated and should not be used anymore.
In standard library there in now zoneinfo that takes over for pytz.

So one more demo,as you mention this timestamp 1679796823.977553 is from Kuala_Lumpur.
The timestamp is always in UTC format,
If you and the guy in Kuala_Lumpur run timestamp script at same time both will be 1679796823.977553 .
But time and Timezone will of course be different

So can just work with UTC time format,or can eg convert as shown under
Using zoneinfo to convert Kuala_Lumpur timestamp to Seattle time.
from datetime import datetime
from zoneinfo import ZoneInfo

from_timezone = ZoneInfo('Asia/Kuala_Lumpur')
to_timezone = ZoneInfo('US/Pacific')

timestamp = 1679796823.977553
dt = datetime.fromtimestamp(timestamp, to_timezone)
result_timestamp = dt.replace(tzinfo=from_timezone).timestamp()
print(dt)
print(result_timestamp)
Output:
2023-03-25 19:13:43.977553-07:00 1679742823.977553
The same with Pendulum.
import pendulum

timestamp = 1679796823.977553
seattle = pendulum.timezone('US/Pacific')
seattle_time = seattle.convert(pendulum.from_timestamp(timestamp))
seattle_timestamp = seattle_time.timestamp()
print(seattle_time.to_datetime_string())
print(seattle_timestamp)
Output:
2023-03-25 19:13:43 1679796823.977553

So if this work can test in reverse,i can take a timestamp at my place now at then run code an it will print the time Kuala Lumpur now.
from datetime import datetime
from zoneinfo import ZoneInfo

from_timezone = ZoneInfo('Europe/Paris')
to_timezone = ZoneInfo('Asia/Kuala_Lumpur')

# I make this timestamp now Norway
timestamp = datetime.now().timestamp()
dt = datetime.fromtimestamp(timestamp, to_timezone)
result_timestamp = dt.replace(tzinfo=from_timezone).timestamp()
print(dt)
print(result_timestamp)
Output:
2023-07-02 20:36:53.733209+08:00 1688323013.733209
Larz60+ likes this post
Reply


Messages In This Thread
RE: Timestamp of file changes if a share mapped to a server…. - by snippsat - Jul-02-2023, 12:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 378 May-03-2024, 07:23 AM
Last Post: Pedroski55
  Trying to access excel file on our sharepoint server but getting errors cubangt 0 892 Feb-16-2023, 08:11 PM
Last Post: cubangt
  How to modify python script to append data on file using sql server 2019? ahmedbarbary 1 1,288 Aug-03-2022, 06:03 AM
Last Post: Pedroski55
  error in timestamp Led_Zeppelin 3 3,386 Jun-15-2022, 08:28 PM
Last Post: deanhystad
  error in timestamp Led_Zeppelin 0 1,070 Jun-10-2022, 07:59 PM
Last Post: Led_Zeppelin
  access share attributed among several class methods drSlump 0 1,119 Nov-18-2021, 03:02 PM
Last Post: drSlump
  |SOLVED] Glob JPGs, read EXIF, update file timestamp? Winfried 5 2,617 Oct-21-2021, 03:29 AM
Last Post: buran
  How to take the tar backup files form remote server to local server sivareddy 0 1,989 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  Move file from one folder to another folder with timestamp added end of file shantanu97 0 2,564 Mar-22-2021, 10:59 AM
Last Post: shantanu97
  How to share a numpy array between 2 processes on Windows? qstdy 0 2,214 Jan-29-2021, 04:24 AM
Last Post: qstdy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020