Connexion avec un réseau social:

How to Convert Python's .isoformat() String Back Into Dateti

How to Convert Python's .isoformat() String Back Into Dateti

Messagepar ABakhsh574711 » 20/09/2022 08:21

How to Convert Python's .isoformat() String Back Into Datetime Object?
.isoformat() is a fantastic tool for transforming any Python DateTime object into an ISO 8601 formatted string. This can be very useful for programmers who want to display dates and times in a specific format without having to Convert Python .isoformat() String Back Into Datetime Object through the effort of formatting it in their own code.
python DateTime to string iso format

Code: Tout sélectionner
from datetime import datetimesome_date = datetime.now()iso_date_string = some_date.isoformat()# For older version of python iso_date_string = some_date.strftime('%Y-%m-%dT%H:%M:%S.%f%z')


python strftime iso 8601

Code: Tout sélectionner
>>> # convert string in iso 8601 date dime format to python datetime type>>> import datetime>>> datetime.datetime.strptime('2020-06-19T15:52:50Z', "%Y-%m-%dT%H:%M:%SZ")datetime.datetime(2020, 6, 19, 15, 52, 50)


datetime.strttime() syntax

Code: Tout sélectionner
from datetime import datetimenow = datetime.now() # current date and timeyear = now.strftime("%Y")print("year:", year)month = now.strftime("%m")print("month:", month)day = now.strftime("%d")print("day:", day)time = now.strftime("%H:%M:%S")print("time:", time)date_time = now.strftime("%m/%d/%Y, %H:%M:%S")print("date and time:",date_time)


The .isoformat() method returns a readable date using the iso-8601 date format. This is useful for giving to users instead of relying on them to enter the date in this format.
ABakhsh574711
Newbie
 
Messages: 2
Enregistré le: 20/09/2022 08:13
Groupe(s):
Utilisateurs enregistrés

Index du forum Ecoles de Commerce, MBAs, MS, MSc, Business Schools et autres formations Ecoles Supérieures de Commerce, Gestion et Management

Articles en relation: How to Convert Python's .isoformat() String Back Into Dateti

  • Articles en relation
    Réponses
    Vus
    Dernier message

Qui est en ligne

Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 0 invités

SUP ETUDES: prepa-HEC.org Admission-Parallele.org coach-entretien.com Ecoles de commerce