File size: 1,947 Bytes
ce5cd7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current date and time:  2017-09-17 11:25:22.307885\n",
      "Current year:  2017\n",
      "Month of year:  September\n",
      "Week number of the year:  37\n",
      "Weekday of the week:  0\n",
      "Day of year:  260\n",
      "Day of the month :  17\n",
      "Day of week:  Sunday\n"
     ]
    }
   ],
   "source": [
    "# Write a Python script to display the various Date Time formats.\n",
    "\n",
    "# a) Current date and time\n",
    "# b) Current year\n",
    "# c) Month of year\n",
    "# d) Week number of the year\n",
    "# e) Weekday of the week\n",
    "# f) Day of year\n",
    "# g) Day of the month\n",
    "# h) Day of week\n",
    "\n",
    "import time\n",
    "import datetime\n",
    "print(\"Current date and time: \" , datetime.datetime.now())\n",
    "print(\"Current year: \", datetime.date.today().strftime(\"%Y\"))\n",
    "print(\"Month of year: \", datetime.date.today().strftime(\"%B\"))\n",
    "print(\"Week number of the year: \", datetime.date.today().strftime(\"%W\"))\n",
    "print(\"Weekday of the week: \", datetime.date.today().strftime(\"%w\"))\n",
    "print(\"Day of year: \", datetime.date.today().strftime(\"%j\"))\n",
    "print(\"Day of the month : \", datetime.date.today().strftime(\"%d\"))\n",
    "print(\"Day of week: \", datetime.date.today().strftime(\"%A\"))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}