Posted On April 19, 2019

Python Module: Datetime

kimconnect 0 comments
blog.KimConnect.com >> Codes >> Python Module: Datetime
Datetime

Programs often include dates and time to perform interactive greetings, calculate age, stamping backups, etc. Here is how to use this class.

import datetime
now = datetime.datetime.now()

# show the day and month using strftime() function
print(now.strftime(%A%m))

For those who are familiar with Linux datetime directives, these symbols will seem very familiar:

Directive Description Example
% Init command character. When precedes itself, becomes escape character. %% => %
%a Abbreviated weekday Wed
%A Weekday Wednesday
%b Abbreviated month name Jan
%B Month name January
%c Copy local date and time Fri Apr 19 13:33:17 2019
%d Day of month 01-31 30
%f Ticks value up to 999999 548513
%H Hour 00-23 (00 is 23 is 2400 hours) 05
%I Hour 00-12 (up to 1300 hours) 05
%j Day number of year 001-366 365
%k hour, 24-hour, leading space as needed, 0-23 _5
%l hour, 12-hour format 1-12 12
%m Month as a number 01-12 12
%M Minute 00-59 41
%p AM/PM PM
%S Second 00-59 08
%U Week number of year, Sunday as the first day of week, 00-53 52
%w Weekday as a number 0-6, 0 is Sunday 3
%W Week number of year, Monday as the first day of week, 00-53 52
%x Local version of date 12/31/18
%X Local version of time 17:41:00
%y Year, short version, without century 18
%Y Year, full version 2018
%z UTC offset +0100
%Z Timezone CST

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Get IP’s From Computer Names

Resolve from Names to IPs: $names=@( 'TESTVM001', 'TESTVM002', 'TESTVM003' ) foreach($name in $names){ $ips =…

PowerShell: Measure File Copying Time

The scripty: $sourcesAndDestinations=@("C:\Users\kimconnect\Desktop\test\test1 C:\Users\kimconnect\Desktop\test\test2","C:\Users\kimconnect\Desktop\test\test2 C:\Users\kimconnect\Desktop\test\test3")$testPath="C:\Users\kimconnect\Desktop\test\test1"$switchesMirrorDirectories="/MIR /SEC /W:3 /FFT "$dateStamp = Get-Date -Format "yyyy-MM-dd-hh-mm"$currentPath=(Get-Item -Path ".\").FullName$log="/LOG+:$currentPath\robocopy-log-$dateStamp.txt"function…

Kubernetes: Cert-Manager Certificate Request YAML Example

# Set variables certPrefix=kimconnect domainName=kimconnect.com domainName2=www.kimconnect.com serviceName=kimconnectblog-wordpress servicePort=8080 # Create a yaml file and create…