1 Star 0 Fork 0

林中白狼 / Console.ActiveMq.Demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
JsonHelper.cs 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
林中白狼 提交于 2019-09-03 16:53 . Initialize
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace ActiveMqConsole
{
public class JsonHelper
{
public static string SerializeToJson(object data, string DateTimeFormats = "yyyy-MM-dd HH:mm:ss")
{
var timeConverter = new IsoDateTimeConverter { DateTimeFormat = DateTimeFormats };
return JsonConvert.SerializeObject(data, Formatting.Indented, timeConverter);
}
/// <summary>
/// 将实体类序列化为JSON
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="data"></param>
/// <returns></returns>
static public string SerializeJSON<T>(T data)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(data);
}
/// <summary>
/// 反序列化JSON
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="json"></param>
/// <returns></returns>
static public T DeserializeJSON<T>(string json)
{
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(json);
}
/// <summary>
/// 日期转换为时间戳(时间戳单位秒)
/// </summary>
/// <param name="TimeStamp"></param>
/// <returns></returns>
public static long ConvertToTimeStamp(DateTime time)
{
DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
return (long) (time.AddHours(-8) - Jan1st1970).TotalMilliseconds;
}
}
}
C#
1
https://gitee.com/fq_chenzhen/Console.ActiveMq.Demo.git
git@gitee.com:fq_chenzhen/Console.ActiveMq.Demo.git
fq_chenzhen
Console.ActiveMq.Demo
Console.ActiveMq.Demo
master

搜索帮助