第一种办法:前端JS转换:

    //格式化显示json日期格式
    function showDate(jsonDate) {
        var date = new Date(jsonDate);
        var formatDate = date.toDateString();
        return formatDate;
    }

第二种办法:

var converters = Configuration.Modules.AbpWebApi().HttpConfiguration.Formatters.JsonFormatter.SerializerSettings.Converters;
           foreach (var converter in converters)
           {
              if (converter is AbpDateTimeConverter)
              {
                  var tmpConverter = converter as AbpDateTimeConverter;
                   tmpConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
              }
}

 第三种办法:

在Application层的根目录添加DateFormat类
/// <inheritdoc />
/// <summary>
/// 日期格式化,格式化 yyyy-MM-dd
/// </summary>
public class DateFormat : IsoDateTimeConverter
{
public DateFormat()
{
base.DateTimeFormat = "yyyy-MM-dd HH:MM:ss";
}
}

第四种办法:

在需要序列化的日期字段添加特性: [JsonConverter(typeof(DateFormat))]
[AutoMapFrom(typeof(Province))]
public class ProvinceDto : EntityDto
{
/// <summary>
/// 省份简称
/// </summary>
public string Code { get; set; }

/// <summary>
/// 城市名称
/// </summary>
public string Name { get; set; }

/// <summary>
/// 创建时间
/// </summary>
[JsonConverter(typeof(DateFormat))]
public DateTime CreateTime { get; set; }
}

 

相关文章:

  • 2021-12-10
  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
猜你喜欢
  • 2022-12-23
  • 2021-04-21
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
  • 2021-12-22
  • 2018-06-19
相关资源
相似解决方案