我试图在本地时间显示日期时间值。默认情况下,Azure SQL数据库在UTC中存储日期和时间,这是无法避免的。(从迁移时,这是一个痛苦的问题。)我想在中欧时间显示一个存储的时间值。
现在当地时间是11:30 (CET)。世界协调时间是10:30。
DECLARE @TestTime DATETIME;
SET @TestTime = '2016-11-02 10:30:00'
SELECT @TestTime
--Returns 2016-11-02 10:30:00
SELECT @TestTime AT TIME ZONE 'Central European St
我已经创建了一些需要测试的DateTime扩展。为了测试它们,我需要能够模拟DateTime实例表示创建实例的本地服务器以外的不同时区。
我试过以下方法..。
//
// Create the new date to test. It will be in the timezone of the server it was created on (EST).
DateTime localDate = new DateTime(2017, 11, 14, 12, 0, 0);
//
// Get the TimeZone for another locale
我有一个有几行的旧表,其中有一个datetime列。我想将它切换到datetimeoffset,但我希望能够传输已经存在的数据。所以我做了一些类似的事情:
SET IDENTITY_INSERT Table_Temp ON
INSERT INTO Table_Temp
(Col0, ... ColN,)
SELECT
COl0,.... ColN, from
Table_Original;
SET IDENTITY_INSERT Table_Temp OFF
这是可行的,但当我执行datetime到datetimeoffset的赋值时,偏移量设置为0。幸运的是,
我对XmlConvert和DateTime有意见。
当使用XmlConvert.ToDateTime(String)转换某些字符串时,然后将结果DateTime转换回使用XmlConvert.ToString(DateTime)的字符串,由此产生的字符串与原始字符串不同,并且取决于本地TimeZone。
下面的控制台应用程序代码演示了这个问题:
using System;
using System.Xml;
namespace DateTimeXmlConvertTest
{
class Program
{
static void Main(string[]
我想保存日期,时间和时区的用户注册时。
我在account表中有一个'signup_date‘列,它在Java中的类型是OffsetDateTime,在liquibase中是Datetime,在PostgreSQL中是timestamp with time zone。
在pgadmin中,我编写了一个插入查询'2019-08-16T20:42:00+03:30‘,但在PostgreSQL中它保存为'2019-08-16 api’,当我通过17:12:00+00获取它时,它返回'2019-08-16T21:42:00+04:30‘。
这一切为什么要发生?
使用javascript,我知道我的用户时区是UTC +3。
现在我想用下面的知识创建DateTime对象:
$usersNow = new DateTime('now', new DateTimeZone("+3"));
我收到以下回复:
'Unknown or bad timezone (+2)'
我做错了什么?我该怎么修复呢?
如何从元组{DD, MM, YY}中创建(Ecto.)DateTime,或者从Elixir中的字符串解析它?我应该使用Erlang中的DateTime吗?
我已经用谷歌搜索过了,但没有找到任何东西,文档中也没有关于这个问题的任何内容,只是关于DateTime的一般信息--例如,如何获取当前的日期和时间。
注意,我不想使用像Timex这样的第三方库。
如果我在WHERE子句中使用DateTime来针对一个字段(即DateTimeOffset )筛选行,会发生什么?
server是否将DateTime字段转换为偏移量为零或.的DateTimeOffset?
例如:
DECLARE @myTime As DateTime = GetDAte()
SELECT *
FROM foo
WHERE @myTime > dbo.foo.TimeStampOffset -- TimeStampOffset is a DateTimeOffset field in foo table
我现在在UTC+1区。TimeZoneInfo.Local.BaseUtcOffset返回+1。
new DateTimeOffset(DateTime.Today).AddDays(4).Offset返回+1。
但是new DateTimeOffset(DateTime.Today.AddDays(4)).Offset返回+2!
更有趣的是,直到加上四天的抵消是一样的。从四天开始,调用new DateTimeOffset(DateTime.Today.AddDays(x)).Offset返回+2偏移量。为什么?
//Same offset +1
var offset2 = new DateT