日/夜圈子示例: 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);
答案 0 :(得分:0)
在PHP中:
$date = new \DateTime();
$date->format('Y-m-d H:i:s'); //returns a string
DateTime对象中还有更多函数; read about it here
在JS中:
var today = new Date();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
然后您可以使用这些值,并使用CSS使用transform: rotate(360deg);
将图像从0-360度旋转