Home > Software design >  How to set a specific future datetime timestamp
How to set a specific future datetime timestamp

Time:10-03

I would LIKe to know how to set a specific DateTime timestamp using the DateTime module in python. For example if I want ... To happen on 1 August 2022. How can I make a DateTime timestamp that will hold that date. Thanks for all help in advance

CodePudding user response:

date fromxxx: https://docs.python.org/3/library/datetime.html#date-objects

date timedelta: Python Get Date In Future (x) Days, And Hours Left To Date?

CodePudding user response:

You can construct a new datetime object with your date (and optionally with time) and then call timestamp() on it. For example, you can do:

from datetime import datetime

timestamp = datetime(2022, 8, 1).timestamp()
# timestamp is now 1659304800.0

You can find the official documentation here.

CodePudding user response:

To create a date, we can use the datetime() class (constructor) of the datetime module.

The datetime() class requires three parameters to create a date: year, month, day.

Example

Create a date object:

import datetime

x = datetime.datetime(2020, 5, 17)

print(x)

source

  • Related