你能否请一下如何从unixtime中删除一小时.
我有一个unixtime,我需要在转换到正常时间之前删除额外的一小时.你能建议怎么做吗?
另外,Unix时间受GMT时间变化的影响吗?
我的服务器正在运行 PHP。我正在使用gmdate()函数将记录从服务器插入到我的数据库中。我只是想知道时区是否通过使用gmdate()功能集中?
例子:
一位用户从印度创建条目并将记录插入到数据库中
和
第二个用户从美国/加拿大/法国创建条目并将记录插入到数据库中。
那个时间和我gmdate()在服务器上插入记录时使用的功能一样吗?
我从 Web 服务获取 json Web 令牌,解码后返回如下内容:
\n{\n "exp": 1572468916,\n "iat": 1572468316,\n "iss": "https://ccc/auth/realms/yyy",\n "aud": "xxx-api",\n [...]\nRun Code Online (Sandbox Code Playgroud)\n根据第 2 节终端学, NumericDate 数据类型对应于“自纪元以来的秒数”
\n所以我将它转换为 JavaScript 日期,如下所示:
\nnew Date(1572468316 * 1000)\nDate Wed Oct 30 2019 17:45:16 GMT-0300 (Argentina Standard Time)\nRun Code Online (Sandbox Code Playgroud)\n问题是我当前的时间是:
\nnew Date()\nDate Wed Oct 30 2019 14:45:19 GMT-0300 (Argentina Standard Time)\nRun Code Online (Sandbox Code Playgroud)\n实际上,当前时间是返回的时间new Date()(即 14:45,不是 17:45)
我猜这与 GMT 有关,但我不知道如何处理它。
\n我想将 iat 属性(显然还有 exp 属性)转换为当前时间,以便将其进行比较以new Date()查明令牌是否已过期。
那么如何将 NumericDate 从 …
我在 SQL 中存储日期时间,该日期时间是从 UTC 格式的 Azure 服务器检索的。
当我从 SQL 检索此日期时间时,日期时间类型未指定......
在英国,我们目前采用 BST,如何根据一年中的时间将从 SQL 收到的日期时间转换为 BST 或 GMT?
我的测试/生产服务器位于在 UTC 上运行的 Azure 中。
回答
感谢@jonathon,我想出了以下扩展方法来解决我的问题。
public static DateTime CovertDateTimeToDateTimeGmt(this DateTime source)
{
var sourceUtc = DateTime.SpecifyKind(source, DateTimeKind.Utc);
var destinationTimezoneId = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
var sourceLocalTime = TimeZoneInfo.ConvertTimeFromUtc(sourceUtc, destinationTimezoneId);
return sourceLocalTime;
}
Run Code Online (Sandbox Code Playgroud)
因为我从 SQL 接收的日期时间没有指定日期时间类型,所以我首先将其转换为指定类型的新日期时间。
我有YYYYMMDD格式的日期字符串,我试图使用日期格式化程序解析成日期
public static DateFormat getDateFormat() {
SimpleDateFormat result = new SimpleDateFormat("yyyyMMdd");
result.setLenient(false);
return result;
}
Run Code Online (Sandbox Code Playgroud)
我在程序运行时设置了默认时区
public static void doTheDateZoneInit() {
TimeZone tzone = TimeZone.getTimeZone("Europe/London");
TimeZone.setDefault(tzone);
}
Run Code Online (Sandbox Code Playgroud)
当我格式化日期并输出它而不在打印字符串中指定时区
Date myDate= getDateFormat().parse("20110331");
System.out.println("Date after it is formatted:" + myDate);
Run Code Online (Sandbox Code Playgroud)
输出位于BST时区
Date after it is formatted:Thu Mar 31 01:00:00 BST 2011
Run Code Online (Sandbox Code Playgroud)
如果我用不同的日期反复运行,我会得到不同的输出
我希望当前日期在GMT明智的时区.我使用以下代码.
public static Date getGMTDate(String dateFormat) throws ParseException
{
SimpleDateFormat dateFormatGmt = new SimpleDateFormat(dateFormat);
dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
// Local time zone
SimpleDateFormat dateFormatLocal = new SimpleDateFormat(dateFormat);
// Time in GMT
return dateFormatLocal.parse(dateFormatGmt.format(new Date()));
}
Run Code Online (Sandbox Code Playgroud)
//调用上面的函数.
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
date = getGMTDate("yyyy-MM-dd HH:mm:ss");
Run Code Online (Sandbox Code Playgroud)
当我更改设备日期时,时间以GMT格式显示,但日期不显示在GMT时区中.显示设备的日期.但我想要当前的GMT日期.
我在托管上有一些PHP脚本,但托管时间与我当地时间不同(GMT + 8)如何设置正确的时间()脚本为GMT + 8?
当我使用:
<?
echo time(); //it show me the hosting time;
?>
Run Code Online (Sandbox Code Playgroud) gmt ×8
java ×3
php ×3
timezone ×3
datetime ×2
time ×2
android ×1
c# ×1
centralized ×1
date ×1
date-format ×1
javascript ×1
jwt ×1
local ×1
utc ×1