目标是创建一个函数,使用Nodatime将时间从一个时区转换为另一个时区.我不只是在寻找关于结果是否正确的反馈,而是针对"我如何"这样做的反馈(这是真的正确,还是有微妙的漏洞).
这是功能:
static ZonedDateTime ConvertDateTimeToDifferentTimeZone(DateTime p_from_datetime, string p_from_zone, string p_to_zone)
{
DateTimeZone from_zone = DateTimeZoneProviders.Tzdb[p_from_zone];
LocalDateTime from_local = new LocalDateTime(p_from_datetime.Year, p_from_datetime.Month, p_from_datetime.Day, p_from_datetime.Hour, p_from_datetime.Minute);
ZonedDateTime from_datetime = from_zone.AtStrictly(from_local);
var from_instant = from_datetime.ToInstant();
DateTimeZone to_zone = DateTimeZoneProviders.Tzdb[p_to_zone];
ZonedDateTime to_datetime = to_zone.AtStrictly(from_local);
var to_offset_datetime = from_instant.WithOffset(to_datetime.Offset);
return to_zone.AtStrictly(to_offset_datetime.LocalDateTime);
}
Run Code Online (Sandbox Code Playgroud)
我称之为的方式如下:
DateTime from_datetime = new DateTime(2016, 10, 15, 16, 30, 0);
string from_zone = "US/Central";
string to_zone = "US/Eastern";
var x = ConvertDateTimeToDifferentTimeZone(from_datetime, from_zone, to_zone);
Console.WriteLine(from_datetime.ToString() + " (" + from_zone + ") …Run Code Online (Sandbox Code Playgroud) 我已使用 SDK 将文件上传到我的私有 S3 存储桶。
我可以通过 S3 UI 访问该文件。
但是,我无法通过直接链接访问该文件。它为我提供了一些 XML,其中包含“AccessDenied”作为代码和消息。
这似乎是合理的,因为我在浏览器中进行了身份验证,并且从同一浏览器单击了指向该文件的直接链接,所以应该允许我通过。至少,我应该被引导至登录页面。
有人对这个有经验么?