GMT形式で時間を自由に変えて表したい「python」
なぜか止まる。
print(str(gmt_0_m)+' test<br>\n')
全文
#!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 -*-
#
point_err = bool(1)
point_return = bool(0)
settig_msgA = 'NO Settig.'
settig_msgB = 'NO Settig.'
error_detail = 'No Error.'
def my_error(error_detail):
if point_err:
print ("Content-type:text/html\n\n")
print ('<!DOCTYPE html><html lang=\"ja\"><head><meta charset=\"UTF-8\"><title>omikuji Error</title></head><body>')
print ('<h1>エラー発生(An error has occurred.)</h1><h2>detail :'+error_detail+'</h2><div style=\"background-color: #000066;color: #cccccc;font-size: 12px;margin: 3px;padding: 3px;\">'+settig_msgA+'</div><div style=\"background-color: #006600;color: #cccccc;font-size: 12px;margin: 3px;padding: 3px;\">'+settig_msgB+'</div><br>')
if point_return:
return
print ('</body></html>\n')
exit()
###################################### この間はprint出力はerrorとなるので my_error("test") を使うこと ##################
# my_error('オープン前エラー Occurrence before opening <b>test.</b>')
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をここから使える ######################
point_return = bool(1) #回帰復帰on
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")
# UTC -> time format
# my (@cpairs, $cname, $cvalue, $value);
# if ($cookie_clr == 1){$COOKIE_LIFE = -1;}
# %COOKIEを単一のクッキー値にエンコード
# foreach $cname (keys %COOKIE) {
# $cvalue = $COOKIE{$cname};
# $cvalue =~ s/(\W)/sprintf("%%%02X", ord $1)/eg;
# push @cpairs, "$cname#$cvalue";
# }
# $value = join('&', @cpairs);
# # グリニッジ標準時の文字列
## my @mon_str = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
## my @wdy_str = qw(Sun Mon Tue Wed Thu Fri Sat);
## my $life = $COOKIE_LIFE * 24 * 60 * 60;
## my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime(time + $life);
## my $date = sprintf("%s, %02d-%s-%04d %02d:%02d:%02d GMT",$wdy_str[$wday],$mday,$mon_str[$mon],$year + 1900,$hour,$min,$sec);
## $coprint = "Set-Cookie: $COOKIE_NAME=$value; expires=$date\n";
# mon_str = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
wdy_str = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
gmt_0_y = int(epoch_0 / (365*24*60*60)) #1970+0y
wike0 = (int(epoch_0 / (24*60*60)) + 4) % 7
week_gmt = wdy_str[wike0] ######
gmt_00_m = epoch_0 - (gmt_0_y*365*24*60*60 + (gmt_0_y -1)*24*60*60)
nit = 24*60*60
my_moon_days00 = [0, 31*nit, 59*nit, 90*nit, 120*nit, 151*nit, 181*nit, 212*nit, 243*nit, 273*nit, 304*nit, 334*nit]
my_moon_days04 = [0, 31*nit, 60*nit, 91*nit, 121*nit, 152*nit, 182*nit, 213*nit, 244*nit, 274*nit, 305*nit, 335*nit]
my_moon_days0 = [0, 31*nit, 59*nit, 90*nit, 120*nit, 151*nit, 181*nit, 212*nit, 243*nit, 273*nit, 304*nit, 334*nit]
if gmt_0_y % 4 == 0:
my_moon_days0 = [0, 31*nit, 60*nit, 91*nit, 121*nit, 152*nit, 182*nit, 213*nit, 244*nit, 274*nit, 305*nit, 335*nit]
#else:
# my_moon_days0= my_moon_days00
print('test '+str(gmt_0_y)+' week_gmt '+week_gmt+'<br>\n')
print('test '+str(my_moon_days0[0]) +' day'+str(gmt_00_m)+'<br>\n')
year_gmt = str(gmt_0_y + 1970) ######
print('年',year_gmt,'<br>\n')
my_m_max = 0
if gmt_00_m >= my_moon_days0[0]:
my_m_max = my_moon_days0[0]
if gmt_00_m >= my_moon_days0[1]:
gmt_0_m += 1
my_m_max = my_moon_days0[1]
if gmt_00_m >= my_moon_days0[2]:
gmt_0_m += 1
my_m_max = my_moon_days0[2]
if gmt_00_m >= my_moon_days0[3]:
gmt_0_m += 1
my_m_max = my_moon_days0[3]
if gmt_00_m >= my_moon_days0[4]:
gmt_0_m += 1
my_m_max = my_moon_days0[4]
if gmt_00_m >= my_moon_days0[5]:
gmt_0_m += 1
my_m_max = my_moon_days0[5]
if gmt_00_m >= my_moon_days0[6]:
gmt_0_m += 1
my_m_max = my_moon_days0[6]
if gmt_00_m >= my_moon_days0[7]:
gmt_0_m += 1
my_m_max = my_moon_days0[7]
if gmt_00_m >= my_moon_days0[8]:
gmt_0_m += 1
my_m_max = my_moon_days0[8]
if gmt_00_m >= my_moon_days0[9]:
gmt_0_m += 1
my_m_max = my_moon_days0[9]
if gmt_00_m >= my_moon_days0[10]:
gmt_0_m += 1
my_m_max = my_moon_days0[10]
if gmt_00_m >= my_moon_days0[11]:
gmt_0_m += 1
my_m_max = my_moon_days0[11]
#my_error('test')
mon_str = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
print('0'+mon_str[0]+'<br>\n')
print(str(gmt_0_m)+' test<br>\n')
moon_gmt = mon_str[gmt_0_m] #####
print('moon',moon_gmt,'0_m',str(gmt_0_m),'<br>\n')
gmt_0_d = int((gmt_00_m - (gmt_0_m*24*60*60))/(24*60*60)) #0day
day_gmt = str(gmt_0_d +1) #####
gmt_0_t = (gmt_00_m - gmt_0_m*24*60*60) - (gmt_0_d*24*60*60) #hms
gmt_0_h = int(gmt_0_t/(60*60)) #h
hour_gmt = str(gmt_0_h) #####
t_m_0 = gmt_0_t - gmt_0_h*60*60
gmt_0_m = int(t_m_0/60) #M
minutes_gmt = str(gmt_0_m) #####
gmt_0_s = t_m_0- gmt_0_m*60 #s
second_gmt = str(gmt_0_s) #####
print('GMT date<br>\n')
print(week_gmt+','+day_gmt+'-'+moon_gmt+'-'+year_gmt+' '+hour_gmt+':'+minutes_gmt+':'+second_gmt+' GMT')
print('<br>\n')
print ('</BODY>'+'\n')
print ('</HTML>'+'\n')
exit()
訳が分かりません、時間ばかりかかってます。
当方、初心者につき、名前付けのルールと言うものを、理解しきれていません。