Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#python の datetime で明日の 時・分をランダムに生成する例 #1238

Open
YumaInaura opened this issue Apr 13, 2019 · 0 comments

Comments

@YumaInaura
Copy link
Owner

>>> import datetime

>>> now = datetime.datetime.now()
>>> now
# datetime.datetime(2019, 4, 13, 18, 44, 57, 269002)

>>> rand_datetime_today = now.replace(hour=random.randint(1,23), minute=random.randint(1,59), second=0, microsecond=0)
>>> rand_datetime_today
# datetime.datetime(2019, 4, 13, 3, 8)

>>> rand_datetime_tomorrow = rand_datetime_today + datetime.timedelta(days=1)
>>> rand_datetime_tomorrow
# datetime.datetime(2019, 4, 14, 3, 8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant