Izip python to string
Hour (12-hour clock) as a decimal number. Hour (12-hour clock) as a zero-padded decimal number. Hour (24-hour clock) as a decimal number.
Hour (24-hour clock) as a zero-padded decimal number. Year without century as a decimal number. Year without century as a zero-padded decimal number. Directiveĭay of the month as a zero-padded decimal. The table below shows all the codes that you can pass to the strftime() method. When you run the program, the output will be: Date time object: 09:55:22
The strftime() method can be used to create formatted strings.The datetime object containing current date and time is stored in now variable.It's because the object of datetime class can access strftime() method. We imported datetime class from the datetime module.The strftime() method takes one or more format codes as an argument and returns a formatted string based on it. Here, year, day, time and date_time are strings, whereas now is a datetime object. When you run the program, the output will something like be: Now = datetime.now() # current date and timeĭate_time = now.strftime("%m/%d/%Y, %H:%M:%S") The program below converts a datetime object containing current date and time to different string formats. The strftime() method returns a string representing date and time using date, time or datetime object.Įxample 1: datetime to string using strftime()