Skip to content

Instantly share code, notes, and snippets.

@ShimanoN
Created February 3, 2023 12:00
Show Gist options
  • Save ShimanoN/b5268196e9f05ebd0005631de56cb73a to your computer and use it in GitHub Desktop.
Save ShimanoN/b5268196e9f05ebd0005631de56cb73a to your computer and use it in GitHub Desktop.
CurrentDate.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"id": "0abd14bb-3991-4a7f-8e83-1b77e4c3a15c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"地球はうまれてから2022回回りました。\n",
"今日は西暦2023年2月3日です。\n"
]
}
],
"source": [
"import datetime\n",
"\n",
"# Today's date\n",
"today = datetime.datetime.now()\n",
"\n",
"# Date of Reiwa era starting (May 1, 2019)\n",
"reiwa_start = datetime.datetime(2019, 5, 1)\n",
"\n",
"# Date of Earth's birth (estimated)\n",
"earth_birth = datetime.datetime(1, 1, 1)\n",
"\n",
"# Calculate the number of days since Earth's birth\n",
"days_since_earth_birth = (today - earth_birth).days\n",
"\n",
"# Calculate the number of orbits around the sun\n",
"orbits = days_since_earth_birth // 365.25\n",
"\n",
"# Calculate the number of days since Reiwa era starting\n",
"days_since_reiwa_start = (today - reiwa_start).days\n",
"\n",
"# Output the result\n",
"print(\"地球はうまれてから{:.0f}回回りました。\".format(orbits))\n",
"print(\"今日は西暦{}年{}月{}日です。\".format(today.year, today.month, today.day))\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment