zoukankan      html  css  js  c++  java
  • 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");
    }
    }
  • 相关阅读:
    ORM是什么?
    mysql 杂谈
    IO model之IO多路复用的触发方式
    IO model之select poll epoll IO多路复用介绍
    IO model
    事件驱动模型介绍
    函数
    商品程序
    随机生成密码
    import radom 和import string
  • 原文地址:https://www.cnblogs.com/xytmj/p/7606886.html
Copyright © 2011-2022 走看看