Python - Date

Card Puncher Data Processing

Example

from datetime import datetime

now = datetime.now()
print now.month
print now.day
print now.year
print str(now.month)+'/'+ str(now.day) + '/'+str(now.year)
print str(now.hour)+':'+ str(now.minute) + ':'+str(now.second)

Conversion

String

def parse_apache_time(s):
    """ 
    Args:
        s (str): date and time in Apache time format
    Returns:
        datetime: datetime object (ignore timezone for now)
    """
    return datetime.datetime(int(s[7:11]),
                             month_map[s[3:6]],
                             int(s[0:2]),
                             int(s[12:14]),
                             int(s[15:17]),
                             int(s[18:20]))





Discover More
Card Puncher Data Processing
Python - Data Type

data (type|structure) in Python of a name generally a variable objecttypeintsstringsfunctionsclassesclass - an integer is a positive or negative whole number. float booleans (True...



Share this page:
Follow us:
Task Runner