zoukankan      html  css  js  c++  java
  • EF 6.0 The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. c#中的时间

    在SQL server 中,有两种日期时间类型:

    1、DateTime 它的范围是 1753-1-1 至 9999-12-31

    2、DateTime2 它的满园是 0001-01-01 至 9999-12-31

    EF实体框架给一个DateTime字段加载一个默认值是 {01/01/0001 00:00:00},它已经在SQL日期类型的范围之外了。所以,如果要让他正常工作,我们需要告诉EF框架不需要创建一个默认的日期时间值。我们可以在模型类型上加一个可空类型,表示它的值是可以为空的。

     [Display(Name = "LastLoggedIn")]
     public DateTime? LastLoggedIn { get; set; }


    日期时间对象创建:

    BirthDate = new DateTime(1990, 6, 1),
    DateTime.Parse("2010/10/1");

    转换日期:
    分为长日期,长时间和短日期和短时间。
    BirthDate.ToString("D") 转换为本地化的时间,如1990年6月1日。
    Birthdate.ToLongDateString()
    BirthDate.ToString("d") 转换为简写的时间。如1990/6/1.
    BithDate.ToShortDateString();

    BithDate.ToString("yyyy-MM-dd")  1990-06-01









  • 相关阅读:
    python爬取北京政府信件信息03
    Python3.7 lxml引入etree
    python爬取北京政府信件信息02
    python爬取北京政府信件信息01
    2020.12.2收获
    2020.12.1收获
    2020.11.30收获
    2020.11.29收获
    2020.11.28收获
    2020.11.27收获
  • 原文地址:https://www.cnblogs.com/liuyuanhao/p/4374030.html
Copyright © 2011-2022 走看看