Time stamped an hour out of sync

One thing I noticed is the csv files my code is creating are being time stamped an hour out of sync.
For example, when I save files at 18:44 my local time they are time stamped as 17:44.
I tried to run this to get around it
```
import pandas as pd
import pytz
from datetime import datetime, timedelta
# Adjust the offset
offset_hours = -6 # Mountain Time (UTC-6)
# Save the DataFrame df to 'eikon.csv' with an adjusted timestamp
output_file = 'eikon.csv'
timestamp = datetime.now() + timedelta(hours=offset_hours)
df.to_csv(output_file, index=False)
print(f"DataFrame saved to '{output_file}' with Mountain Time timestamp:", timestamp)
# Create the 'cam' DataFrame and save it to 'cam.csv'
cam_output_file = 'cam.csv'
cam_df = df[['TICKER', 'CAM']].copy()
cam_df.columns = ['ticker', 'cam']
cam_df.to_csv(cam_output_file, index=False)
print(f"'cam' DataFrame saved to '{cam_output_file}' with Mountain Time timestamp:", timestamp)
```
But it had no effect. I'm not seeing anything unusual in the logs or debugging console to indicate the cause of this.
This is not a major issue as it does not specifically affect my code, but it may have unforeseen effects on others, so I'm bringing it to your attention.
Best Answer
-
Hi @Jenan
Instead of hard-coding the offset, try this:
mountain_time = utc_time.astimezone(pytz.timezone("America/Denver"))
Should be 7 hours difference MST and 6 MDT.
0
Answers
-
Thank you for reaching out to us.
I ran the following code on CodeBook.
from datetime import datetime, timedelta
offset_hours = -6 # Mountain Time (UTC-6)
now = datetime.now()
timestamp = now + timedelta(hours=offset_hours)
print(f"UTC:\t{now}")
print(f"UTC-6:\t{timestamp}")The output is:
The value of timestamp is correct (UTC-6).
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 690 Datastream
- 1.4K DSS
- 629 Eikon COM
- 5.2K Eikon Data APIs
- 11 Electronic Trading
- 1 Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 255 ETA
- 559 WebSocket API
- 39 FX Venues
- 15 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 25 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 279 Open PermID
- 45 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 23 RDMS
- 2K Refinitiv Data Platform
- 716 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 106 UPA
- 194 TREP Infrastructure
- 229 TRKD
- 918 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 95 Workspace SDK
- 11 Element Framework
- 5 Grid
- 19 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛