热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

时区应该是常数还是变量?-Shouldthetimezonebeaconstantoravariable?

IhaveafewplacesinthecodewhereIneedtousetheTimeZone.Icangetthetimezonenameusing

I have a few places in the code where I need to use the TimeZone. I can get the timezone name using DateTime::TimeZone. Is it reasonable to put the timezone name in a constant? Or should it be in a variable?

我在代码中有几个地方需要使用TimeZone。我可以使用DateTime :: TimeZone获取时区名称。将时区名称放在常量中是否合理?或者它应该在变量中?

3 个解决方案

#1


5  

If the value can change, use a variable, of it is guaranteed to stay the same, use a constant.

如果值可以更改,则使用变量,保证保持不变,使用常量。

For a timezone, the chance it will change is not big, but it is also not 0. The user can change the timezone and it would be nice if the program behaves accordingly.

对于一个时区,它改变的机会并不大,但它也不是0.用户可以改变时区,如果程序的行为相应会很好。

#2


3  

I vote for variable. You could end up with different users in different timezones working with your application, even if you doubt that could ever happen. It happened to me a couple of years ago.

我投票给变量。即使您怀疑可能发生这种情况,您最终可能会在使用您的应用程序的不同时区中与不同的用户结束。几年前它发生在我身上。

#3


2  

Look at where the timezone is coming from. Is it the timezone of a city? Make it constant. Is it the timezone of the user? Make it variable - we users travel all the time, and we reset the timezone on our laptops so that Outlook scheduling will work correctly at the new location.

看看时区的来源。它是一个城市的时区吗?让它保持不变。是用户的时区吗?让它变化 - 我们的用户一直在旅行,我们在笔记本电脑上重置时区,以便Outlook调度在新位置正常工作。


推荐阅读
author-avatar
亲爱的jackvan叔叔
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有