秒のエポック標準時を算出する。
#!c:/Python3/python -X utf8
# coding=utf-8
#######################################################################################
# DATA 2024/02/11 エポック標準時刻を表示する
# this script http://127.0.0.1/my_python/python_time1.cgi
#
########################################################################################
# test on *.py
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
#
import datetime
print ('Content-type:text/html'+'\n'+'\n')
print ('<!DOCTYPE html><html lang=\"ja\"><head><meta charset=\"UTF-8\"><title>pyton_v5</title>'+'\n')
# print ('<link rel=\"stylesheet\" href=\"popupw_css.css\">'+'\n')
print ('<script src=\"python_time.js\" defer></script>'+'\n')
print ('</head><BODY BGCOLOR=\"#ffffff\">'+'\n')
point_err = bool(0) #ここから後はヘッダータグを打ち出さなくていい。########### printをここから使える ######################
print ('エポック標準時の比較<br>\n')
now = datetime.datetime.now()
#my_date = now.strftime("%Y/%m/%d %H:%M:%S")
my_year = int(now.strftime("%Y"))-1970
my_month = int(now.strftime("%m"))-1
my_day = int(now.strftime("%d"))-1
my_hour =int(now.strftime("%H"))
my_minute = int(now.strftime("%M"))
my_second = int(now.strftime("%S"))
def_moon_days = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
def_moon_days4 = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335]
if my_year%4 == 0:
my_moon_days = def_moon_days4[my_month]
else:
my_moon_days = def_moon_days[my_month]
epoch_tokyo = 9
print("1:javascript<div id=\"mymy\"></div>\n")
my_year2 = int(my_year/4)
epoch_0 = my_year*365*24*60*60 + (my_moon_days + my_day+my_year2)*24*60*60 + (my_hour-epoch_tokyo)*60*60 + my_minute*60 + my_second
print("2:python計算<div id=\"mymy1\">",epoch_0,"</div>\n")
print("3:差<div id=\"mymy2\"></div>\n")
print('<br>\n')
epoch_1 = epoch_0 + 9*60*60
print(epoch_1," Epo_tokyo<br>\n")
print ('</BODY>'+'\n')
print ('</HTML>'+'\n')
exit()
検証のためのjavascropt python_time.js
/* test time */
my_jst_Epo= Math.floor(Date.now()/1000);
document.getElementById("mymy").innerHTML = my_jst_Epo;
my_py_Epo = document.getElementById("mymy1").innerHTML;
my0 = parseInt(my_py_Epo);
my_sa = my_jst_Epo - parseInt(my_py_Epo);
my_sa /=24*60*60;
document.getElementById("mymy2").innerHTML = String(my_sa);
仕様書が無いので自己流です。逆算も、そのうちやりたいとは思っています。