【发布时间】:2019-01-29 19:09:43
【问题描述】:
昼/夜圈示例: https://i.ibb.co/fFskJ28/exmp.png
我希望日/夜圆圈图像(上面链接中的示例)根据实时(+1 UTC,没有冬/夏时间调整)旋转。您在图像中看到的时间已经基于 +1 UTC 时间。 我已经在我的游戏制作项目中实现了这项工作,但现在我还想要在我的网站上显示这个昼/夜循环图像,以便访问者也可以在那里看到昼/夜循环。
我已经有了用 GML 编写的工作代码,但现在我想要它在 PHP/Javascript 中,我对 Javascript 了解不多,但我想如果我想要日/夜循环图像,它是必须使用的实时旋转。
这是我用 GML 编写的工作代码:
//written in GML
// unix_timestamp([datetime])
//
// Returns a Unix timestamp for the current time
// or optionally given GameMaker datetime value.
{
var timezone = date_get_timezone();
date_set_timezone(timezone_utc);
if (argument_count > 0) {
var datetime = argument[0];
} else {
var datetime = date_current_datetime();
}
var timestamp = round(date_second_span(25569, datetime));
date_set_timezone(timezone);
return timestamp;
}
以下部分有点乱,但我想做的都是我想要的,使变量“小时”和“分钟”等于我所在国家/地区的实时小时/分钟(+1 UTC)
//written in GML
rtime = unix_timestamp();
//removing all seconds from 1 jan 1970 00:00 - 1 jan 2019 00:00 (UTC+1 Amsterdam)
rtime2 = (rtime - 1546300800+3600);//the +3600 is meant to add 1 hour to
equalise to the UTC+1 time
//remove all remaining days
{
while (rtime2 >= 86400)
{
rtime2 -= 86400;
}
}
dtime = unix_timestamp();
//removing all seconds from 1 jan 1970 00:00 - 1 jan 2019 00:00 (UTC+1 Amsterdam)
dtime2 = (dtime - 1546300800+3600);//the +3600 is meant to add 1 hour to
equalise to the UTC+1 time
//number of days from 1 jan 2019 00:00
day_unf = (dtime2 / 86400);
day = (floor(day_unf) + 1);
//count all remaining hours
hour_unf = (rtime2 / 3600);
hour = (floor(hour_unf))
qtime = unix_timestamp();
//removing all seconds from 1 jan 1970 00:00 - 1 jan 2019 00:00 (UTC+1 Amsterdam)
qtime2 = (qtime - 1546300800+3600);//the +3600 is meant to add 1 hour to
equalise to the UTC+1 time
//remove all remaining days
{
while (qtime2 >= 86400)
{
qtime2 -= 86400;
}
}
removar = (hour * 60)
//count all remaining minutes
minute_unf = (qtime2 / 60);
minute_unf2 = (minute_unf - removar);
minute = (floor(minute_unf2))
xtime = unix_timestamp();
//removing all seconds from 1 jan 1970 00:00 - 1 jan 2019 00:00 (UTC+1 Amsterdam)
xtime2 = (xtime - 1546300800+3600);//the +3600 is meant to add 1 hour to
equalise to the UTC+1 time
//remove all remaining days
{
while (xtime2 >= 86400)
{
xtime2 -= 86400;
}
}
rem = (minute * 60);
rem2_unf = (hour * 3600);
xtime3 = (xtime2 - rem);
second = (xtime3 - rem2_unf);
if hour == 24{
hour = 0;
}
//written in GML
pre1 = 15 * hour;
pre2 = 0.25 * minute;
pre3 = pre1 + pre2;
cycle_angle = pre3;
//cycle_angle is always a number between 0-360 and is used below to draw the day/night circle image in the right rotation degree.
draw_sprite_ext(spr_day_night_cycle,0,960,80,image_xscale*1.5,image_yscale*1.5,cycle_angle,c_white,image_alpha);
由于图像是一个 360° 的圆,它代表一整天 24 小时的时间,每经过一小时等于旋转 15°,每分钟等于旋转 0.25°。 例如,当时间是 18:30 时,它会旋转 277,5° (15 * 18 + 30 * 0.25) 表示今天是白天,但日落很近。
所以我的问题是:
问题 1: 如何根据我所在国家/地区的实时小时/分钟(+1UTC,没有冬季/夏季时间)在 PHP/Javascript 中创建变量“小时”和“分钟”需要调整)
问题 2: 如果我在问题 1 中成功,我如何像在 GML 中那样根据“小时”和“分钟”变量在网站上旋转我的日/夜圆圈图像? (参见下面的 GML 示例)
//written in GML
pre1 = 15 * hour;
pre2 = 0.25 * minute;
pre3 = pre1 + pre2;
cycle_angle = pre3;
//cycle_angle is always a number between 0-360 and is used below to draw the day/night circle image in the right rotation degree.
draw_sprite_ext(spr_day_night_cycle,0,960,80,image_xscale*1.5,image_yscale*1.5,cycle_angle,c_white,image_alpha);
【问题讨论】:
标签: javascript unix time gml