1 添加扩展方类与扩展方法
public static class HttpConfigurationExtension { /// <summary> /// 将返回JSON内容的日期格式成:yyyy-MM-dd HH:mm:ss /// </summary> public static void DateFormat(this HttpConfiguration config) { config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss", }); } }
2 在Global里使用:
public static void Register(HttpConfiguration config) { config.DateFormat(); }