Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
767 views
in Technique[技术] by (71.8m points)

timezone - PHP TZ setting length

I was wonder what is the maximum length of the timezone settings in PHP? I'm storing the string in a database, and would like to keep the length as short as possible, but i see timezones like "Canada/East-Saskatchewan", which goes beyond our current limit.

If I could just get a list of all the supported timezone string, I can sort them, but they are currently split on to several different pages.

linky: http://www.php.net/manual/en/timezones.php

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Edit June 2021 Answer is 64. Why? That's the width of the column used in MySQL to store those timezone name strings.

The zoneinfo database behind those time zone strings just added new prefixes. To America/Argentina/ComodRivadavia, formerly the longest timezone string, they added posix/America/Argentina/ComodRivadavia and right/America/Argentina/ComodRivadavia, both with a length of 38. This is up from 32, the previous longest string.

And here is the complete PHP code to find that:

<?php
$timezone_identifiers = DateTimeZone::listIdentifiers();

$maxlen = 0;
foreach($timezone_identifiers as $id)
{
    if(strlen($id) > $maxlen)
        $maxlen = strlen($id);
}

echo "Max Length: $maxlen";

/*
Output:

Max Length: 32

*/
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...