python timestamp to datetime with YY-MM-dd HH:mm
Jump to turn (11)
- 1python timestamp to datetime with YY-MM-dd HH:mm
- 2i want to display the datetimes on an plt, but theres now an black shape at the
- 3my dates array is from type timestamp
- 4359 np.timedelta64(int(np.round(x MUSECONDSPERDAY)), 'us')) 360 if dt = np.datet
- 5the x axis shows 01: 00:00 for %d: %h:%m
- 6name 'timedelta' is not defined
- 7No artists with labels found to put in legend. Note that artists whose label sta
- 8is pandas dataframe describe
- 9how to describe an scattered line
- 10with code
- 11is there a function to get a random color for multiplot
- User
python timestamp to datetime with YY-MM-dd HH:mm
- Assistant
To convert a timestamp to a datetime object in Python formatted as "YY-MM-dd HH:mm," you can use the
datetimemodule. Here's how you can do it:pythonfrom datetime import datetime # Example timestamp timestamp = 1683010445 # This is a Unix timestamp # Convert timestamp to datetime object dt_object = datetime.fromtimestamp(timestamp) # Format datetime object as "YY-MM-dd HH:mm" formatted_date = dt_object.strftime("%y-%m-%d %H:%M") print(formatted_date)Replace
1683010445with your actual timestamp value. This code snippet takes a Unix timestamp, converts it to a datetime object, and then formats the datetime object as a string in the "YY-MM-dd HH:mm" format.