简体   繁体   English

EF Core 3.0,日期时间时区问题 C#

[英]EF Core 3.0, Datetime timezone issue C#

The datetime stored in the DB(postgresql) is with time zone(EST), while binding the value to code it is getting converted to system local time(IST), Even while trying to fetch it as string using convertors the value get converted to local time and display at string存储在数据库(postgresql)中的日期时间与时区(EST)一起,同时将值绑定到代码,它被转换为系统本地时间(IST),即使在尝试使用转换器将其作为字符串获取时,值也会被转换为本地时间并以字符串显示

Please help on how to ignore the Timezone in the ModelBuilder请帮助了解如何忽略模型构建器中的时区

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<TblData>(entity =>
    {

        var converter = new ValueConverter<DateTime, DateTime>(
                   v => new DateTime(),
                   v => DateTimeOffset.Parse(v.ToString()).DateTime);

        var converter1 = new ValueConverter<string, DateTime>(
                   v => new DateTime(),
                   v => v.ToString());

        entity.Property(e => e.StartTime)
                               .HasColumnName("start_time")
                               .HasColumnType("timestamp(4) with time zone");
                               .HasConversion(converter);

        //both converters return value in localtime only
    }
}

a zone specific time conversion is not possible as the API layer is dealing with multiple timezone DB's and API is deployed in both Linux and windows server. a zone specific time conversion is not possible as the API layer is dealing with multiple timezone DB's and API is deployed in both Linux and windows server.

Please help !!!请帮忙 !!!

I usually set the TZ of the db user.我通常设置db用户的TZ。

ALTER ROLE my_db_user IN DATABASE my_database
    SET "TimeZone" TO 'UTC';

Will this be of any use?这会有用吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM