将文本时区转换为缩写,例如将 ‘America/New_York’ 转换为 ‘EST’。

huangapple go评论54阅读模式
英文:

PHP convert text timezome to abbreviated ? like 'America/New_York' to 'EST'

问题

是的,您可以将数据库中的时区文本格式轻松显示为3个字符的形式。

英文:

so i have timezone in my DB in text format - is there a way to easily display is as the 3 character form ?

答案1

得分: 0

在PHP中,您可以像这样实现:

<?php
    $timezoneText = '太平洋标准时间'; // 或者您所使用的时区
    $timezone = new DateTimeZone($timezoneText);
    $currentTime = new DateTime('now', $timezone);
    $abbreviation = $currentTime->format('T');
    echo $abbreviation;
?>
英文:

In php you can do it like this

&lt;?php
    $timezoneText = &#39;Pacific Standard Time&#39;; // or whatever you have
    $timezone = new DateTimeZone($timezoneText);
    $currentTime = new DateTime(&#39;now&#39;, $timezone);
    $abbreviation = $currentTime-&gt;format(&#39;T&#39;);
    echo $abbreviation;
?&gt;

huangapple
  • 本文由 发表于 2023年6月27日 21:13:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76565264.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定