Skip to content

Instantly share code, notes, and snippets.

@thesaadarshad
Last active March 31, 2018 15:01
Show Gist options
  • Save thesaadarshad/ccd7d34f12b3692ca5bf583c00149001 to your computer and use it in GitHub Desktop.
Save thesaadarshad/ccd7d34f12b3692ca5bf583c00149001 to your computer and use it in GitHub Desktop.

Revisions

  1. thesaadarshad revised this gist Mar 31, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion datetime.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@

    import datetime

    now = datetime.datetime.now()

  2. thesaadarshad created this gist Mar 31, 2018.
    25 changes: 25 additions & 0 deletions datetime.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@


    now = datetime.datetime.now()

    print
    print "Current date and time using str method of datetime object:"
    print str(now)

    print
    print "Current date and time using instance attributes:"
    print "Current year: %d" % now.year
    print "Current month: %d" % now.month
    print "Current day: %d" % now.day
    print "Current hour: %d" % now.hour
    print "Current minute: %d" % now.minute
    print "Current second: %d" % now.second
    print "Current microsecond: %d" % now.microsecond

    print
    print "Current date and time using strftime:"
    print now.strftime("%Y-%m-%d %H:%M")

    print
    print "Current date and time using isoformat:"
    print now.isoformat()