有一串json字符串,我需要将其中的时间格式从yyyy-M-d转换为yyyy/M/d,用c#的正则表达式替换的方法怎么写

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了有一串json字符串,我需要将其中的时间格式从yyyy-M-d转换为yyyy/M/d,用c#的正则表达式替换的方法怎么写相关的知识,希望对你有一定的参考价值。

如下2015-9-24转换为2015/9/24
["Data":null,"Time":"2015-9-24 0:00:00","Data":null,"Time":"2015-9-24 1:00:00","Data":null,"Time":"2015-9-24 2:00:00","Data":null,"Time":"2015-9-24 3:00:00","Data":null,"Time":"2015-9-24 4:00:00","Data":null,"Time":"2015-9-24 5:00:00","Data":null,"Time":"2015-9-24 6:00:00","Data":null,"Time":"2015-9-24 7:00:00","Data":null,"Time":"2015-9-24 8:00:00","Data":null,"Time":"2015-9-24 9:00:00","Data":null,"Time":"2015-9-24 10:00:00","Data":null,"Time":"2015-9-24 11:00:00","Data":null,"Time":"2015-9-24 12:00:00","Data":null,"Time":"2015-9-24 13:00:00","Data":null,"Time":"2015-9-24 14:00:00","Data":null,"Time":"2015-9-24 15:00:00","Data":null,"Time":"2015-9-24 16:00:00","Data":null,"Time":"2015-9-24 17:00:00","Data":null,"Time":"2015-9-24 18:00:00","Data":null,"Time":"2015-9-24 19:00:00","Data":null,"Time":"2015-9-24 20:00:00","Data":null,"Time":"2015-9-24 21:00:00","Data":null,"Time":"2015-9-24 22:00:00","Data":null,"Time":"2015-9-24 23:00:00","Data":null,"Time":"2015-9-25 0:00:00"]

 String s = "[\\"Data\\":null,\\"Time\\":\\"2015-9-24 0:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 1:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 2:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 3:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 4:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 5:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 6:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 7:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 8:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 9:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 10:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 11:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 12:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 13:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 14:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 15:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 16:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 17:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 18:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 19:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 20:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 21:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 22:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-24 23:00:00\\",\\"Data\\":null,\\"Time\\":\\"2015-9-25 0:00:00\\"]";
            Console.WriteLine(s);
            String s0 = Regex.Replace(s, "([0-9]4)-([0-9]1,2)-([0-9]1,2)", "$1/$2/$3");
            Console.WriteLine(s0);

参考技术A

你先试试查找是否成功再说:

201\\d-\\d-[123]\\d [\\d:]7

以上是关于有一串json字符串,我需要将其中的时间格式从yyyy-M-d转换为yyyy/M/d,用c#的正则表达式替换的方法怎么写的主要内容,如果未能解决你的问题,请参考以下文章

Oracle时间一串数字转为日期格式

在 jquery 数据表中显示之前将 json 日期格式化为 mm/dd/yy 格式

如何显示可以从一串数字创建的所有IP地址组合?

将字符串dd / mm / yy转换为datetime

SQL日期格式转换? [dd.mm.yy 到 YYYY-MM-DD]

如何过滤多维 JSON 对象