til

Today I Learned: collection of notes, tips and tricks and stuff I learn from day to day working with computers and technology as an open source contributor and product manager

View project on GitHub

strftime

I was working with jq when I was reading some documentation which referenced strftime, when googling I found this Python resource, which helped me, even though I should probably have found one in JavaScript anyway, this one worked for me.

strftime can convert a DateTime object to a string in a given format.

from datetime import datetime

now = datetime.now() # current date and time

year = 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)

Resources and References