- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
Datetime Methods
The sorted() Method:
- The sorted() method uses to put the earlier string date in the first order, and the later string date in the second order.- In the below code, we take three dates in the dates list, we can take more dates into a list.
The replace() Method:
- The replace() method replaces a specific date or time with a new date or time.- In the below code, we changed the month and minute in the replace_dt variable.
The fromtimestamp() Method:
- Timestamp: Number of seconds.- Python will read timestamps and return a datetime.
- We call the fromtimestamp() method to the datetime module in the print function.
The isoformat() 8601 Method:
- The isoformat() 8601 method returns the date and time format as iso format.- Return ISO Format for a date (YYYY-MM-DD)
- Return ISO Format for datetime (YYYY-MM-DDTHH:MM:SS)
- In ISO Format, the date requires 3 parameters, and datetime requires 6 parameters.
The strftime() Method:
- The strftime() method turn dates into a string.- The strftime() method required one parameter.
- %Y Code, means return the Year in Full Form of the given date.
- %m Code, means return the month of the given date.
- %d Code, means return the day of the given date.
- To use the above codes put the code in the string in the strftime method.
(See in the below Code)
- Get link
- X
- Other Apps
Comments
Post a Comment