電日(E-Day)轉換器

刷新

電日 > 日期

電日:
in

日期 > 電日

日期: - - : : :
表示代碼

In Python:

import time, datetime

def e2d(eday):
    return datetime.datetime.utcfromtimestamp(eday*86400)

def d2e(date):
    return time.mktime(date.utctimetuple())/86400

A) Variant (Python >=3.9)

import datetime as dt
import zoneinfo as zf

# date -> eday
dt.datetime(YYYY, DD, MM, HH, MM, tzinfo=zf.ZoneInfo("SOURCE_ZONE")).astimezone(zf.ZoneInfo("UTC")).timestamp()/86400

# eday -> date
dt.datetime.fromtimestamp(YOUR_EDAY*86400).astimezone(zf.ZoneInfo("TARGET_ZONE"))

B) Variant

import datetime as dt
import pytz as tz

# date -> eday
tz.timezone("SOURCE_ZONE").localize(dt.datetime(YYYY, MM, DD, HH, MM), is_dst=None).astimezone(tz.utc).timestamp()/86400

# eday -> date
dt.datetime.fromtimestamp(YOUR_EDAY*86400).astimezone(tz.timezone("TARGET_ZONE"))