{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2019-08-28 14:25:35.711200\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "now = datetime.now()\n",
    "print(now)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %a : Weekday as locale’s abbreviated name.<br>\n",
    "Example:<br>\n",
    "Sun, Mon, …, Sat (en_US);<br>\n",
    "So, Mo, …, Sa (de_DE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Weekday as locale’s abbreviated name: Wed\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%a\") \n",
    "print(\"Weekday as locale’s abbreviated name:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %A : Weekday as locale’s full name<br>\n",
    "Example:<br>\n",
    "Sunday, Monday, …, Saturday (en_US);<br>\n",
    "Sonntag, Montag, …, Samstag (de_DE)<br>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Weekday as locale’s full name: Wednesday\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%A\") \n",
    "print(\"Weekday as locale’s full name:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %w: Weekday as a decimal number, where 0 is Sunday and 6 is Saturday.<br>\n",
    "Example:<br>\n",
    "0, 1, …, 6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Weekday as a decimal number: 3\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%w\") \n",
    "print(\"Weekday as a decimal number:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %d: Day of the month as a zero-padded decimal number.<br>\n",
    "Example:<br>\n",
    "01, 02, …, 31"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Day of the month as a zero-padded decimal number: 28\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%d\") \n",
    "print(\"Day of the month as a zero-padded decimal number:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %b: Month as locale’s abbreviated name.<br>\n",
    "Example:<br>\n",
    "Jan, Feb, …, Dec (en_US);<br>\n",
    "Jan, Feb, …, Dez (de_DE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Month as locale's abbreviated name: Aug\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%b\") \n",
    "print(\"Month as locale's abbreviated name:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %B: Month as locale’s full name.<br>\n",
    "Example: <br>\n",
    "January, February, …, December (en_US);<br>\n",
    "Januar, Februar, …, Dezember (de_DE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Month as locale's full Name: August\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%B\") \n",
    "print(\"Month as locale's full Name:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %m: Month as a zero-padded decimal number.<br>\n",
    "Example:<br>\n",
    "01, 02, …, 12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Month as a zero-padded decimal number: 08\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%m\") \n",
    "print(\"Month as a zero-padded decimal number:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %y: Year without century as a zero-padded decimal number.<br>\n",
    "Example:<br>\n",
    "00, 01, …, 99"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Year without century as a zero-padded decimal number: 19\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%y\") \n",
    "print(\"Year without century as a zero-padded decimal number:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %Y: Year with century as a decimal number.<br>\n",
    "Example:<br>\n",
    "0001, 0002, …, 2013, 2014, …, 9998, 9999"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Year with century as a decimal number: 2019\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%Y\") \n",
    "print(\"Year with century as a decimal number:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %H: Hour (24-hour clock) as a zero-padded decimal number.<br>\n",
    "Example:<br>\n",
    "00, 01, …, 23"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hour as a zero-padded decimal number: 14\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%H\") \n",
    "print(\"Hour as a zero-padded decimal number:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %I: Hour (12-hour clock) as a zero-padded decimal number.<br>\n",
    "Example:<br>\n",
    "01, 02, …, 12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hour as a zero-paddes decimal number: 02\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%I\") \n",
    "print(\"Hour as a zero-paddes decimal number:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %p: Locale’s equivalent of either AM or PM.<br>\n",
    "Example:<br>\n",
    "AM, PM (en_US);<br>\n",
    "am, pm (de_DE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Locale's equivalent of either AM Or PM: PM\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%p\") \n",
    "print(\"Locale's equivalent of either AM Or PM:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %M: Minute as a zero-padded decimal number.<br>\n",
    "Example:<br>\n",
    "00, 01, …, 59"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Minute as a zero-padded decimal number: 25\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%M\") \n",
    "print(\"Minute as a zero-padded decimal number:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %S: Second as a zero-padded decimal number.<br>\n",
    "Example:<br>\n",
    "00, 01, …, 59"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Second as a zero-padded decimal number: 35\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%S\") \n",
    "print(\"Second as a zero-padded decimal number:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %f: Microsecond as a decimal number, zero-padded on the left.<br>\n",
    "Example:<br>\n",
    "000000, 000001, …, 999999"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Microsecond as a decimal number, zero-padded on the left: 711200\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%f\") \n",
    "print(\"Microsecond as a decimal number, zero-padded on the left:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %z: UTC offset in the form ±HHMM[SS[.ffffff]] (empty string if the object is naive).<br>\n",
    "Example:<br>\n",
    "(empty), +0000, -0400, +1030, +063415, -030712.345216"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "UTC offset in the form ±HHMM[SS[.ffffff]]: +0100\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "from datetime import time, tzinfo, timedelta\n",
    "class TZ1(tzinfo):\n",
    "   def utcoffset(self, dt):\n",
    "      return timedelta(hours=1)\n",
    "   def dst(self, dt):\n",
    "      return timedelta(0)\n",
    "   def tzname(self,dt):\n",
    "      return \"+01:00\"\n",
    "   def  __repr__(self):\n",
    "      return f\"{self.__class__.__name__}()\"\n",
    "t = time(10, 8, 55, tzinfo=TZ1())\n",
    "day = t.strftime(\"%z\") \n",
    "print(\"UTC offset in the form ±HHMM[SS[.ffffff]]:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %Z: Time zone name (empty string if the object is naive).<br>\n",
    "Example:<br>\n",
    "(empty), UTC, EST, CST"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time zone name: +01:00\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "from datetime import time, tzinfo, timedelta\n",
    "class TZ1(tzinfo):\n",
    "   def utcoffset(self, dt):\n",
    "      return timedelta(hours=1)\n",
    "   def dst(self, dt):\n",
    "      return timedelta(0)\n",
    "   def tzname(self,dt):\n",
    "      return \"+01:00\"\n",
    "   def  __repr__(self):\n",
    "      return f\"{self.__class__.__name__}()\"\n",
    "t = time(10, 8, 55, tzinfo=TZ1())\n",
    "day = t.strftime(\"%Z\")\n",
    "print(\"Time zone name:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %j: Day of the year as a zero-padded decimal number.<br>\n",
    "Example:<br>\n",
    "001, 002, …, 366"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Day of the year as a zero-padded decimal number: 240\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%j\") \n",
    "print(\"Day of the year as a zero-padded decimal number:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %U: Week number of the year (Sunday as the first day of the week) as a zero padded decimal number.<br> All days in a new year preceding the first Sunday are considered to be in week 0.<br>\n",
    "Example:<br>\n",
    "00, 01, …, 53"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Week number of the year as a zero-padded decimal number: 34\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%U\") \n",
    "print(\"Week number of the year as a zero-padded decimal number:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %W: Week number of the year (Monday as the first day of the week) as a decimal number.<br> All days in a new year preceding the first Monday are considered to be in week 0.<br>\n",
    "Example:<br>\n",
    "00, 01, …, 53    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Week number of the year as a zero-padded decimal number: 34\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%W\") \n",
    "print(\"Week number of the year as a zero-padded decimal number:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %c: Locale’s appropriate date and time representation.<br>\n",
    "Example:<br>\n",
    "Tue Aug 16 21:30:00 1988 (en_US);<br>\n",
    "Di 16 Aug 21:30:00 1988 (de_DE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Locale's appropriate date and time representation: Wed Aug 28 14:25:35 2019\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%c\") \n",
    "print(\"Locale's appropriate date and time representation:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %x: Locale’s appropriate date representation.<br>\n",
    "Example:<br>\n",
    "08/16/88 (None);<br>\n",
    "08/16/1988 (en_US);<br>\n",
    "16.08.1988 (de_DE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Locale's appropriate date representation: 08/28/19\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%x\") \n",
    "print(\"Locale's appropriate date representation:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %X: Locale’s appropriate time representation.<br>\n",
    "Example:<br>\n",
    "21:30:00 (en_US);<br>\n",
    "21:30:00 (de_DE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Locale's appropriate time representation: 14:25:35\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%X\") \n",
    "print(\"Locale's appropriate time representation:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %%: A literal '%' character.<br>\n",
    "Example:<br>\n",
    "%"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A literal '%' character: %\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%%\") \n",
    "print(\"A literal '%' character:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Several additional directives not required by the C89 standard are included for convenience.<br> These parameters all correspond to ISO 8601 date values. These may not be available on all platforms when used with the strftime() method.<br> The ISO 8601 year and ISO 8601 week directives are not interchangeable with the year and week number directives above.<br> Calling strptime() with incomplete or ambiguous ISO 8601 directives will raise a ValueError."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %G: ISO 8601 year with century representing the year that contains the greater part of the ISO week (%V).<br>\n",
    "Example:<br>\n",
    "0001, 0002, …, 2013, 2014, …, 9998, 9999"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ISO 8601 year with century representing the year that contains the greater part of the ISO week: 2019\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%G\") \n",
    "print(\"ISO 8601 year with century representing the year that contains the greater part of the ISO week:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %u: ISO 8601 weekday as a decimal number where 1 is Monday.<br>\n",
    "Example:<br>\n",
    "1, 2, …, 7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ISO 8601 weekday as a decimal number where 1 is Monday: 3\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "now = datetime.now()\n",
    "day = now.strftime(\"%u\") \n",
    "print(\"ISO 8601 weekday as a decimal number where 1 is Monday:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Code - %V: ISO 8601 week as a decimal number with Monday as the first day of the week. Week 01 is the week containing Jan 4.<br>\n",
    "Example:<br>\n",
    "01, 02, …, 53"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ISO 8601 week as a decimal number with Monday as the first day of the week.: 35\n"
     ]
    }
   ],
   "source": [
    "day = now.strftime(\"%V\") \n",
    "print(\"ISO 8601 week as a decimal number with Monday as the first day of the week.:\", day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "New in version 3.6: %G, %u and %V were added."
   ]
  }
 ],
 "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.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
