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: Scan a Subnet for Used and Unused IPs

A newer version of this script is available here. function scanForAvailableIPs{ param( $cidrBlock=$( $interfaceIndex=(Get-WmiObject -Class…

PowerShell: Microsoft Dynamics Update All Organizations

# updateCrmOrgs.ps1 function updateCrmOrgs{ try{ Add-PSSnapin Microsoft.Crm.Powershell $servers=Get-CrmServer $highestVersion=($servers.Version|measure-object -Maximum).Maximum $lowVersionServers=$servers|?{[version]$_.Version -lt [version]$highestVersion} if($lowVersionServers){ write-warning…

Basic CSS: Add Different Margins to Each Side of an Element

<style>.injected-text {margin-bottom: -25px;text-align: center;}.box {border-style: solid;border-color: black;border-width: 5px;text-align: center;}.yellow-box {background-color: yellow;padding: 10px;}.red-box {background-color: crimson;color: #fff;margin-top:…
Other project: DragonCoin.com