current position:Home>Get the current time in Python

Get the current time in Python

2022-05-15 05:49:33A small pit of goods

python Get the current time


python Built in modules time, You can get the current time , Make records to facilitate the use of replication method when writing code .

""" @Description:  Get the current time  """
import time


def get_now_datetime():
    """ @Description:  Return current time , The format is : Mm / DD / yyyy HHM / S  """
    return time.strftime('%Y-%m-%d-%H_%M_%S',time.localtime(time.time()))

def get_now_time():
    """ @Description:  Return current time , The format is : Minutes and seconds  """
    return time.strftime('%H-%M-%S',time.localtime(time.time()))

def get_now_date():
    """ @Description:  Return current time , The format is : Specific date  """
    return time.strftime('%Y-%m-%d',time.localtime(time.time()))


if __name__=='__main__':
    print(get_now_datetime())
    print(get_now_date())
    print(get_now_time())

copyright notice
author[A small pit of goods],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/135/202205142240049532.html

Random recommended