zoukankan      html  css  js  c++  java
  • [转]Newtonsoft JSON how to dynamically change the date format?

    本文转自:http://www.howtobuildsoftware.com/index.php/how-do/cg8K/jsonnet-newtonsoft-json-how-to-dynamically-change-the-date-format

    I'm using Newtonsoft JSON Serializer and it's great and super fast but I'd like to do a bit more with it. I'm not sure it's possible as all the search I've done comes up to nothing. What I would like is to be able to truncate empty time, so when it's display 2014-01-01 00:00:00.000 I just want 2014-01-01 at the end, so basically cut the entire time when they're all zeros. For now I use this piece of code:

    DataTable dt = loadData();
    
    // encode the string with Newton JSON.Net 
    string output = JsonConvert.SerializeObject(dt,
        new JsonSerializerSettings
        {
            ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
            Formatting = Newtonsoft.Json.Formatting.None,
            DateFormatString = "yyyy-MM-dd HH:mm:ss"
        });
    

    Is there a way to format these dates without the time (only when they are all zeros) without affecting the performance?

  • 相关阅读:
    手动创建分区以及软硬raid的问题
    实用小工具:VNC的安装
    安装使用xen虚拟化工具
    使用vsftp与shell实现对进程与服务状态的监控
    windows server2008下搭建ftp服务
    业界虚拟化技术分析
    Android命名规范(自定义)
    Android Paint和Color类
    Android 应用中十大常见 UX 错误
    漫谈互联网产品设计之人性的弱点,你躺枪了木有?
  • 原文地址:https://www.cnblogs.com/freeliver54/p/6893120.html
Copyright © 2011-2022 走看看