Časové funkce v Pythonu | Sada 2 (manipulace s datem)
Některé z časových funkcí jsou diskutovány v Sada 1 Manipulaci s datem lze také provádět pomocí Pythonu pomocí modulu 'datetime' a pomocí třídy 'date' v něm. Operace k datu: 1. MILOLET :- Zobrazuje minimální rok které lze reprezentovat pomocí třídy data. 2. MAXYEAR :- Zobrazuje maximální rok that can be represented using date class. Python
3. datum (rrrr-mm-dd) :- Tato funkce vrací řetězec s předanými argumenty v pořadí rok měsíců a datum. 4. dnes() :- Vrátí datum dnešního dne in the format yyyy-mm-dd. Python
5. fromtimestamp (s) :- Vrátí to datum počítané z sekund uplynulo od epochy uvedené v argumentech. 6. min() :- Toto vrátí minimální datum která může být reprezentována třídou data. 7. max() :- Toto vrátí maximální datum that can be represented by date class. Python
# Python code to demonstrate the working of # MINYEAR and MAXYEAR # importing built in module datetime import datetime from datetime import date # using MINYEAR to print minimum representable year print ( 'Minimum representable year is : ' end = '' ) print ( datetime . MINYEAR ) # using MAXYEAR to print maximum representable year print ( 'Maximum representable year is : ' end = '' ) print ( datetime . MAXYEAR )
Output: Minimum representable year is : 1 Maximum representable year is : 9999
3. datum (rrrr-mm-dd) :- Tato funkce vrací řetězec s předanými argumenty v pořadí rok měsíců a datum. 4. dnes() :- Vrátí datum dnešního dne in the format yyyy-mm-dd. Python
# Python code to demonstrate the working of # date() and today() # importing built in module datetime import datetime from datetime import date # using date() to represent date print ( 'The represented date is : ' end = '' ) print ( datetime . date ( 1997 4 1 )) # using today() to print present date print ( 'Present date is : ' end = '' ) print ( date . today ())
Output: The represented date is : 1997-04-01 Present date is : 2016-08-02
5. fromtimestamp (s) :- Vrátí to datum počítané z sekund uplynulo od epochy uvedené v argumentech. 6. min() :- Toto vrátí minimální datum která může být reprezentována třídou data. 7. max() :- Toto vrátí maximální datum that can be represented by date class. Python
# Python code to demonstrate the working of # fromtimestamp() min() and max() # importing built in module datetime import datetime from datetime import date # using fromtimestamp() to calculate date print ( 'The calculated date from seconds is : ' end = '' ) print ( date . fromtimestamp ( 3452435 )) # using min() to print minimum representable date print ( 'Minimum representable date is : ' end = '' ) print ( date . min ) # using max() to print minimum representable date print ( 'Maximum representable date is : ' end = '' ) print ( date . max )
Output: The calculated date from seconds is : 1970-02-09 Minimum representable date is : 0001-01-01 Maximum representable date is : 9999-12-31