- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我目前正在使用一个开源应用程序:WeBid(可用 here)
问题是:
应用程序无法正确计算 DST(夏令时),因为它使用了以下代码:
(包括/functions_global.php)
$this->ctime = time() + (($this->SETTINGS['timecorrection'] + gmdate('I')) * 3600);
$this->tdiff = ($this->SETTINGS['timecorrection'] + gmdate('I')) * 3600;
gtpotyf 解释说:
gmdate('I') -> Returns 1 if DST is active, 0 if not active. However since gmdate always uses GMT(+0) and that timezone has no DST it will always return 0.
using date('I') instead of gmdate('I') would work better, but would still not be correct since it uses the timezone from the server and still not the users timezone.
WeBid最新版本未采用最终修正,请帮我解决这个问题。
最佳答案
为了正确地整理时区,您需要做一些事情。
将您的服务器设置为 UTC,以便 PHP 的 time
和 date
函数返回 UTC 时间戳。 (除了 strftime
等相关函数。
根据您的数据库,您也可以将其时区设置为 UTC。 MySQL 关于这个主题的文档是 here .
您需要将存储在其中的日期时间迁移到 UTC(如果尚未迁移)。 (我不确定你所说的 GMT-0 是什么意思。)
让用户选择 PHP 的 DateTimeZone 类支持的“欧洲/伦敦”格式的时区。
经过一些研究,我将以下时区数组组合在一起,在下拉框中呈现给用户,因为我不想重复(例如,阿姆斯特丹和布鲁塞尔位于同一时区。)我不会声称它是完美的。根据您的用户群,您可能想要更详细地调查某些时区。
$timezones = array(
'Pacific/Midway' => '(UTC-11:00) Midway Island, Samoa',
'Pacific/Honolulu' => '(UTC-10:00) Hawaii-Aleutian',
'Pacific/Marquesas' => '(UTC-09:30) Marquesas Islands',
'Pacific/Gambier' => '(UTC-09:00) Gambier Islands',
'America/Anchorage' => '(UTC-09:00) Alaska',
'America/Ensenada' => '(UTC-08:00) Tijuana, Baja California',
'Etc/GMT+8' => '(UTC-08:00) Pitcairn Islands',
'America/Los_Angeles' => '(UTC-08:00) Pacific Time (US & Canada)',
'America/Denver' => '(UTC-07:00) Mountain Time (US & Canada)',
'America/Chihuahua' => '(UTC-07:00) Chihuahua, La Paz, Mazatlan',
'America/Dawson_Creek' => '(UTC-07:00) Arizona',
'America/Belize' => '(UTC-06:00) Saskatchewan, Central America',
'America/Cancun' => '(UTC-06:00) Guadalajara, Mexico City, Monterrey',
'Chile/EasterIsland' => '(UTC-06:00) Easter Island',
'America/Chicago' => '(UTC-06:00) Central Time (US & Canada)',
'America/New_York' => '(UTC-05:00) Eastern Time (US & Canada)',
'America/Havana' => '(UTC-05:00) Cuba',
'America/Bogota' => '(UTC-05:00) Bogota, Lima, Quito, Rio Branco',
'America/Caracas' => '(UTC-04:30) Caracas',
'America/Santiago' => '(UTC-04:00) Santiago',
'America/La_Paz' => '(UTC-04:00) La Paz',
'Atlantic/Stanley' => '(UTC-04:00) Falkland Islands',
'America/Campo_Grande' => '(UTC-04:00) Brazil',
'America/Goose_Bay' => '(UTC-04:00) Atlantic Time (Goose Bay)',
'America/Glace_Bay' => '(UTC-04:00) Atlantic Time (Canada)',
'America/St_Johns' => '(UTC-03:30) Newfoundland',
'America/Araguaina' => '(UTC-03:00) UTC-3',
'America/Montevideo' => '(UTC-03:00) Montevideo',
'America/Miquelon' => '(UTC-03:00) Miquelon, St. Pierre',
'America/Godthab' => '(UTC-03:00) Greenland',
'America/Argentina/Buenos_Aires' => '(UTC-03:00) Buenos Aires',
'America/Sao_Paulo' => '(UTC-03:00) Brasilia',
'America/Noronha' => '(UTC-02:00) Mid-Atlantic',
'Atlantic/Cape_Verde' => '(UTC-01:00) Cape Verde Is.',
'Atlantic/Azores' => '(UTC-01:00) Azores',
'Europe/Dublin' => '(UTC) Irish Standard Time : Dublin',
'Europe/Lisbon' => '(UTC) Western European Time : Lisbon',
'Europe/London' => '(GMT) Greenwich Mean Time : London, Belfast',
'Africa/Abidjan' => '(GMT) Monrovia, Reykjavik',
'Europe/Amsterdam' => '(UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna',
'Europe/Belgrade' => '(UTC+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague',
'Europe/Brussels' => '(UTC+01:00) Brussels, Copenhagen, Madrid, Paris',
'Africa/Algiers' => '(UTC+01:00) West Central Africa',
'Africa/Windhoek' => '(UTC+01:00) Windhoek',
'Asia/Beirut' => '(UTC+02:00) Beirut',
'Africa/Cairo' => '(UTC+02:00) Cairo',
'Asia/Gaza' => '(UTC+02:00) Gaza',
'Africa/Johannesburg' => '(UTC+02:00) Johannesburg, Harare, Pretoria',
'Asia/Jerusalem' => '(UTC+02:00) Jerusalem',
'Europe/Athens' => '(UTC+02:00) Athens',
'Europe/Minsk' => '(UTC+02:00) Minsk',
'Asia/Damascus' => '(UTC+02:00) Syria',
'Europe/Moscow' => '(UTC+03:00) Moscow, St. Petersburg, Volgograd',
'Africa/Addis_Ababa' => '(UTC+03:00) Nairobi',
'Asia/Tehran' => '(UTC+03:30) Tehran',
'Asia/Dubai' => '(UTC+04:00) Abu Dhabi, Muscat',
'Asia/Yerevan' => '(UTC+04:00) Yerevan',
'Asia/Kabul' => '(UTC+04:30) Kabul',
'Asia/Yekaterinburg' => '(UTC+05:00) Ekaterinburg',
'Asia/Tashkent' => '(UTC+05:00) Tashkent',
'Asia/Kolkata' => '(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi',
'Asia/Katmandu' => '(UTC+05:45) Kathmandu',
'Asia/Dhaka' => '(UTC+06:00) Astana, Dhaka',
'Asia/Novosibirsk' => '(UTC+06:00) Novosibirsk',
'Asia/Rangoon' => '(UTC+06:30) Yangon (Rangoon)',
'Asia/Bangkok' => '(UTC+07:00) Bangkok, Hanoi, Jakarta',
'Asia/Krasnoyarsk' => '(UTC+07:00) Krasnoyarsk',
'Asia/Hong_Kong' => '(UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi',
'Asia/Irkutsk' => '(UTC+08:00) Irkutsk, Ulaan Bataar',
'Australia/Perth' => '(UTC+08:00) Perth',
'Australia/Eucla' => '(UTC+08:45) Eucla',
'Asia/Tokyo' => '(UTC+09:00) Osaka, Sapporo, Tokyo',
'Asia/Seoul' => '(UTC+09:00) Seoul',
'Asia/Yakutsk' => '(UTC+09:00) Yakutsk',
'Australia/Adelaide' => '(UTC+09:30) Adelaide',
'Australia/Darwin' => '(UTC+09:30) Darwin',
'Australia/Sydney' => '(UTC+10:00) Sydney, Canberra, Brisbane',
'Australia/Hobart' => '(UTC+10:00) Hobart',
'Asia/Vladivostok' => '(UTC+10:00) Vladivostok',
'Australia/Lord_Howe' => '(UTC+10:30) Lord Howe Island',
'Etc/GMT-11' => '(UTC+11:00) Solomon Is., New Caledonia',
'Asia/Magadan' => '(UTC+11:00) Magadan',
'Pacific/Norfolk' => '(UTC+11:30) Norfolk Island',
'Asia/Anadyr' => '(UTC+12:00) Anadyr, Kamchatka',
'Pacific/Auckland' => '(UTC+12:00) Auckland, Wellington',
'Etc/GMT-12' => '(UTC+12:00) Fiji, Kamchatka, Marshall Is.',
'Pacific/Chatham' => '(UTC+12:45) Chatham Islands',
'Pacific/Tongatapu' => '(UTC+13:00) Nuku Alofa',
'Pacific/Kiritimati' => '(UTC+14:00) Kiritimati'
);
当日期从您的数据库中出来时,需要将它们从 UTC 转换为用户的时区。
$timestamp = time(); // or a timestamp from your DB
# create server and user timezone objects
$fromZone = new DateTimeZone('UTC'); // UTC
$toZone = new DateTimeZone($userTimezone); // Europe/London, or whatever it happens to be
$time = date('Y-m-d H:i:s', $timestamp);
$dt = new DateTime($time, $fromZone);
echo $dt->format('Y-m-d H:i:s'); // Still UTC
$dt->setTimezone($toZone);
echo $dt->format('Y-m-d H:i:s'); // Converted
您需要浏览 WeBid 应用程序并修改适当的部分以正确转换。
因此,使用上面的代码,您需要一些函数来执行以下操作:
function getConvertedDateTimeObject($timestamp, $userTimezone){
# create server and user timezone objects
$fromZone = new DateTimeZone('UTC'); // UTC
$toZone = new DateTimeZone($userTimezone); // Europe/London, or whatever it happens to be
$time = date('Y-m-d H:i:s', $timestamp);
$dt = new DateTime($time, $fromZone);
$dt->setTimezone($toZone);
return $dt;
}
function getUserTimestamp($timestamp, $userTimezone){
$dt = getConvertedDateTimeObject($timestamp, $userTimezone);
return $dt->getTimestamp();
}
function getUserOffset($timestamp, $userTimezone){
$dt = getConvertedDateTimeObject($timestamp, $userTimezone);
return $dt->getOffset();
}
然后在你的类里面:
$this->ctime = getUserTimestamp(time(), $userTimezone); // I assume you have access to the user's timezone?
$this->tdiff = getUserOffset(time(), $userTimezone);
关于php - WeBid : Timezones with daylight savings time not calculated correctly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11890894/
我正在从tangowithdjango学习django 。我试图理解 populate_rango.py 的代码。代码是: import os os.environ.setdefault('DJANG
我试图理解Rserve参数--save,-no-save和--vanilla之间的区别。我在文档或任何论坛中都没有看到任何描述这些效果的内容。有谁确切地知道这些是做什么的? 在OSX中,我需要指定其中
我正在使用 CoreData 制作一个基于文档的应用程序。我可以创建一个新文档,编辑该文档,然后保存它。文件已创建并可以打开。打开后,数据会正确加载。但是,一旦进行了初始保存,所有后续保存都不会执行任
下面提出了类似的问题 How to save complete web page 但目前还没有答案。预期的结果是得到很多文件,一些文件来存储图像等。 我使用了以下内容,它会弹出一个窗口说保存文件 va
我们一直在测试一种不同的保存方式。然而,结果并不像我们预期的那样。我们有创建调查的方法,每个调查有多个问题。我们测试了几个案例,它们都以相同的方式提交查询。 @Transactional class
我想了解JAP Repotitoty的详细信息。我创建了一个服务类、实体类和存储库类,如下所示(用 kotlin 编写)并执行了 ItemService#update 方法。 执行 item2Repo
我正在开发我的第一个 Firefox 扩展。我正在尝试将数据保存在浏览器的本地存储中(使用 Window.localStorage 很容易,但我正在关注 official recommandation
这让我很郁闷。我是 C Sharp 的新手,因此需要一些帮助。我的保存/另存为完全是胡说八道。 真的有两个问题: 如何在不弹出保存对话框的情况下保存对现有文件的更改?如果我单击“保存”,它会弹出一个对
我有一个代码可以将 XML 文件保存到我的目录中。它在我的本地主机和我的共享主机中实际上就像一个魅力,但它在我的 Linux VPS 中不起作用。 我总是遇到这个错误: 警告:DOMDocument:
有没有办法在 django 管理站点中同时“另存为”和“保存并添加另一个”? 最佳答案 我不认为按钮引用的 URL 有任何神奇之处,因此您可以通过简单地覆盖每个 http://docs.djangop
创建 playramework 的模型时,我们可以使用 save() 或 _save() 方法。为什么这两种方法在框架中都可用,原因是什么? (在这种情况下,他们做同样的事情 - 将对象保存到数据库)
我见过两个都调用 $save 的代码和 save到 $resource 的 Angular 。 有什么区别,你什么时候使用? 最佳答案 最佳解释===例子 : // by writing '{ id:
根据save bang your head, active record will drive you mad ,在特殊情况下我们应该避免使用 save! 和 rescue 习惯用法。鉴于此,假设模型
我的菜单栏中有两个按钮,其中包含“保存”和“另存为”按钮。但是,我目前拥有它们相同的代码,并且它会按当前方式保存,并提示用户要保存在哪里。我希望保存按钮仅保存而不提示对话框,除非文件尚不存在。 我尝试
我知道 models.Model 和 forms.ModelForm 都包含您可以覆盖的 .save() 方法。我的问题是它们如何以及何时用于保存对象以及以什么顺序。 最佳答案 ModelForm.s
我一直在尝试使用 freeze_graph函数来获取模型+权重/偏差,但在这个过程中,我发现我的初始网络似乎没有任何变量,尽管能够正确分类图像。我的代码如下: #!/usr/bin/python im
尝试使用 gTTS 模块将文本转换为语音并另存为 wav 文件。 我的代码: import gTTS text = "This is my text in the saving folder" tts
我有一个包含大约 50 个字段和两个提交按钮的表单,“保存”和“保存并提交”。如果用户单击“保存”,则插入用户在表格中填写的值。当用户单击“保存并提交”按钮时,它应该更新或插入用户在表单中填写的所有字
我是 Django 新手。我想知道 django 中的 ModelForm 和 Model 如何协同工作?我的意思是 ModelForm.save() 如何自动保存与之关联的模型?它如何从 reque
我有亲子关系: @Entity @Table(name = "user") public final class User { @Id @GeneratedValue(strategy
我是一名优秀的程序员,十分优秀!