根据在 html 下拉列表中选择的国家/地区填写当前时间

Fill the current time based on the selection of the country in html dropdown

本文关键字:地区 时间 国家 html 下拉列表 选择      更新时间:2023-09-26

>我有一个 HTML 下拉菜单,其中指定了国家/地区名称。还有另一个字段指定了日期时间字段。

当用户选择一个国家/地区时,我希望日期时间字段填充该特定国家/地区的当前日期时间。请让我知道可以通过什么方式以及如何做到这一点。

提前谢谢。

一种方法是获取带有 $( "#myselect option:selected" ).text(); 的 select 标记的国家/地区名称或带有 $( "#myselect" ).val(); 的值,然后使用 switch 语句更改日期时间字段。

第 1 步:列出所有时区,使用,

$timezone_identifiers = DateTimeZone::listIdentifiers();
for ($i=0; $i < 20; $i++) {
    echo "$timezone_identifiers[$i]";
}

第 2 步:获取该特定时区的时间,

date_default_timezone_set('Africa/Algiersn');
echo $date= date('Y-m-d H:i:s');

参考: http://www.php.net/manual/en/datetimezone.listidentifiers.php