问题标签 [localtime]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
10911 浏览

c# - 将 UTC 日期时间全局转换为用户指定的本地日期时间

我将所有 DateTime 字段存储为 UTC 时间。当用户请求网页时,我想采用他首选的本地时区(而不是服务器机器的本地时区)并自动将所有 Web 表单中的所有 DateTime 字段显示为本地日期。

当然,我可以在每个表单中的每个 DateTime.ToString() 调用上应用转换,或者实现一些辅助实用程序,但这是一项耗时的任务,而且还有一些第 3 方组件很难使用自定义 DateTime 显示模板进行配置.

本质上,我想让 DateTime 类的行为如下:

有什么办法吗?

顺便说一句,如果重要的话,我正在使用 ASP.NET MVC 4。

0 投票
1 回答
1179 浏览

wordpress - 按访客计算机时区显示日期和时间

我希望将我的 wordpress 帖子和评论日期和时间转换为访问者计算机时区。这样,用户应该知道他的当地时间创建的确切时间帖子或评论。

我知道当你为搜索引擎和访问者展示不同的东西时,隐藏是不好的 seo 做法。可以认为是伪装吗?这种做法会影响搜索引擎优化吗?

0 投票
1 回答
272 浏览

python-2.7 - python localtime 导入时间

我的问题是根据消息获取小时数。但我只得到开始时间,因为?time.sleep 是模拟传入消息的时间。为什么不给不同的时间表?

0 投票
2 回答
1227 浏览

php - PHP 显示本地时间(静态)并考虑夏令时/冬令时

我目前正在尝试显示 10 个不同时区的当地时间,但我找不到任何解决我的问题的方法。

我正在使用这段代码:

$timezone本地时间在哪里,取决于时区,可以是 、 或无+-我的问题是,有些国家有夏令时。我怎样才能让这段代码考虑到这一点并计算夏季/冬季?

0 投票
2 回答
2148 浏览

php - php 通过时区代码/数字(+1、+2 等)获取本地时间

我正在努力寻找解决方案,无论如何我可以使用 php 或 js/jquery 函数/插件根据其时区代码获取城市或州的当地时间吗?例如,假设罗马是时区 2

十分感谢。

0 投票
3 回答
319 浏览

c - 结构 tm 在另一个结构内 - c

mktime我正在尝试使用和计算两个日期之间的日期差异difftime。其中一个日期是struct tminside 另一个struct,另一个日期是struct tminside mainmktime里面的日期可以正常工作main,但在struct. 我想我忽略了一些关于如何访问struct内部的非常明显的东西,struct但我找不到答案。提前致谢。

代码如下

0 投票
1 回答
849 浏览

c++ - 为什么在调用 localtime() 函数之前不需要 malloc struct tm 指针?

我的代码是

我怀疑用于存储 struct tm 的内存地址在哪里。

0 投票
1 回答
328 浏览

c - 使用 GDateTime 而不是 localtime_r

在这段代码中使用 GDateTime 而不是 localtime_r 有什么好处:

0 投票
1 回答
7536 浏览

c++ - localtime and asctime are unsafe, but the safe functions don't have the same parameters

I'm attempting to create timestamps for my program. On my sister's Mac (using Xcode 4.2) this code works perfectly fine:

However, on my PC running Visual Studio 2012 I get errors for localtime and asctime that tell me they are unsafe functions and it recommends using localtime_s and asctime_s. However, the function parameters are different. I've tried researching the functions as best I can, but I can't get it to work.

Any help with getting that to work would be much appreciated.

edit:

0 投票
0 回答
114 浏览

silverlight - silverlight datagrid 显示当地时间

我在silverlight datagrid中以这种方式绑定日期,它会转换为当地时间吗?

这似乎对我不起作用。例如,如果香港用户查询“2013 年 8 月 9 日”的数据,服务器将其转换为世界时为“2013 年 8 月 8 日”并返回给客户端。但上述绑定不会将其转换回 '09-Aug-2013' 仍显示为 '08-Aug-2013'