abp允许跨域代码,时间转换为固定格式,本地时间

 在Global的 Application_BeginRequest方法中:

Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CN");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN");

在WebApiModule的Initialize()方法里面添加下面代码:

//跨域代码
GlobalConfiguration.Configuration.EnableCors(new EnableCorsAttribute("*", "*", "*"));

 

//Json时间格式化


Clock.Provider = ClockProviders.Local;


GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";

 

GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Where(x => x is Abp.Json.AbpDateTimeConverter).AsEnumerable().ToList().ForEach(x =>
{
(x as Abp.Json.AbpDateTimeConverter).DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
});

如果不起作用:

可以在实体类里面:通过属性赋值时强制转换:

string creationTime;
/// <summary>
/// 创建时间
/// </summary>
public string CreationTime
{
get
{
if (this.Id == 0)
{
return "";
}
return creationTime;
}
set
{
creationTime = String.IsNullOrEmpty(value) ? "" : (DateTime.Parse(value)).ToString("yyyy-MM-dd HH:mm:ss");
}
}
原文地址:https://www.cnblogs.com/xytmj/p/7606886.html