Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

time conversion in python

import datetime

x = datetime.datetime.now()
print("Now Time = ",x.strftime("%H:%M:%S %p"))
print(x.strftime("Date = %d"))
print(x.strftime("Weekday = %A"))
print(x.strftime("Month = %B"))
print(x.strftime("Year = %Y"))


# There is more to know-

print("Time = ",x.strftime("%H:%M:%S %p"))
print("Full name Year  = ",x.year)
print(x.strftime("Full name Month  = %B"))
print(x.strftime("Full name Day = %A"))
print(x.strftime("Date of Month(01-31) = %d"))
print(x.strftime("Weekday, short version = %a"))
print(x.strftime("Weekday as a number(0-6) = %w"))
print(x.strftime("Month name short = %b"))
print(x.strftime("Month as number = %m"))
print(x.strftime("Short name Year = %y"))
print(x.strftime("Full Year name = %Y"))
print(x.strftime("Time Zone = %Z"))
print(x.strftime("Local Date = %x"))
print(x.strftime("Lacal Date time = %X"))
print(x.strftime("Local date and time = %c"))

# All Varsion Datetime System:
#A reference of all the legal format codes:
'''
Directive:	                                   Description:	                                                       Example:     

%a         ---------                    Weekday, short version                ---------                =   Wed

%A        ---------                     Weekday, full version                  ---------           = Wednesday

%w        ---------           Weekday as a number 0-6, 0 is Sunday      -------           =      3

%d        ---------                     Day of month 01-31                 ---------                       =    31

%b           ---------                  Month name, short version	       ---------                  =   Dec

%B           ---------                  Month name, full version	        ---------             = December

%m        ---------                 Month as a number 01-12        ---------                     =     12

%y        ---------                Year, short version, without century        ---------        = 18

%Y        ---------                    Year, full version           ---------                                =  2018

%H        ---------                     Hour 00-23                      ---------                           =    17

%I        ---------                     Hour 00-12	        ---------                                 =   05

%p        ---------                     AM/PM	        ---------                              =     PM

%M        ---------                     Minute 00-59	        ---------                               =     41

%S        ---------                     Second 00-59	        ---------                                 =   08

%f        ---------                     Microsecond 000000-999999        ---------        =	548513

%z        ---------                     UTC offset        ---------                                      =      +0100

%Z        ---------                     Timezone	        ---------                             =      CST

%j        ---------                     Day number of year 001-366            ---------        =  365

%U   ---------  Week number of year, Sunday as the first day of week, 00-53--------- = 52

%W   --------- Week number of year, Monday as the first day of week, 00-53 --------  = 52

%c        ---------      Local version of date and time        ---------             =  Mon Dec 31 17:41:00 2018	

%x        ---------                     Local version of date	        ---------              =  12/31/18	

%X        ---------                     Local version of time	        ---------              =  17:41:00	

%%        ---------                     A % character	                       ---------                 =    %	

%G        ---------                     ISO 8601 year                          ---------                    =      2018	

%u        ---------                     ISO 8601 weekday (1-7)            ---------                 =   1	

%V           ---------             ISO 8601 weeknumber (01-53)	        ---------              = 01

'''
Comment

PREVIOUS NEXT
Code Example
Python :: how to print error in try except python 
Python :: delete column pandas dataframe 
Python :: where to import messages in django 
Python :: python 1 second delay 
Python :: install fastapi conda 
Python :: time it python 
Python :: column dataframe to int 
Python :: python get utc time 
Python :: python kivy Kivy files require #:kivy ! 
Python :: resize imshow opencv python 
Python :: python write json to file utf8 
Python :: check filed exist in object python 
Python :: imshow grayscale 
Python :: python text tkinter not typable 
Python :: AssertionError: Torch not compiled with CUDA enabled 
Python :: conda install xgboost 
Python :: python datetime string 
Python :: django previous url 
Python :: shutdown/restart/hibernate/logoff windows with python 
Python :: python iterate list reverse 
Python :: color to black and white cv2 
Python :: python reload file if changed 
Python :: export dataframe to csv python 
Python :: linux python installation wheel 
Python :: opencv draw a point 
Python :: DeprecationWarning: executable_path has been deprecated, please pass in a Service object 
Python :: invert dictionary python 
Python :: index in zip python 
Python :: pytorch check if cuda is available 
Python :: import csv file using pandas 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =