在elastic的请求下,我得到一个带有json格式时间戳的json。 但我想以C#DateTime格式/对象获取它。 如何将json时间戳转换为C#DateTime ?
坦率
我现在得到什么:
{“ timestamp”:“ {\ r \ n \” month \“:3,\ r \ n \” hour \“:21,\ r \ n \” nanosecond \“:0,\ r \ n \“ year \”:2019,\ r \ n \“ isNull \”:否,\ r \ n \“毫秒”:0.0,\ r \ n \“ value \”:\“ 2019-03-02T21: 22:29 \“,\ r \ n \” day \“:2,\ r \ n \” binData \“:\” eHcDAhYXHgAAAAA = \“,\ r \ n \” minute \“:22,\ r \ n \“ second \”:29 \ r \ n}“,
我想拥有什么:
“ 2019年2月3日21:22:29 PM”
答案 0 :(得分:1)
您可以使用JSON.NET这样尝试:
onError: io.grpc.StatusRuntimeException: INTERNAL: Panic! This is a bug!
2019-03-20 17:30:32.485 25247-25293/com.logicvalley.translator E/ManagedChannelImpl: [Channel<1>: (speech.googleapis.com:443)] Uncaught exception in the SynchronizationContext. Panic!
java.lang.AbstractMethodError: abstract method "io.grpc.internal.ConnectionClientTransport io.grpc.internal.ClientTransportFactory.newClientTransport(java.net.SocketAddress, io.grpc.internal.ClientTransportFactory$ClientTransportOptions)"
at io.grpc.internal.CallCredentialsApplyingTransportFactory.newClientTransport(CallCredentialsApplyingTransportFactory.java:47)
at io.grpc.internal.InternalSubchannel.startNewTransport(InternalSubchannel.java:262)
at io.grpc.internal.InternalSubchannel.obtainActiveTransport(InternalSubchannel.java:215)
at io.grpc.internal.ManagedChannelImpl$SubchannelImpl.requestConnection(ManagedChannelImpl.java:1438)
at io.grpc.internal.PickFirstLoadBalancer.handleResolvedAddressGroups(PickFirstLoadBalancer.java:59)
at io.grpc.internal.AutoConfiguredLoadBalancerFactory$AutoConfiguredLoadBalancer.handleResolvedAddressGroups(AutoConfiguredLoadBalancerFactory.java:149)
at io.grpc.internal.ManagedChannelImpl$NameResolverListenerImpl$1NamesResolved.run(ManagedChannelImpl.java:1312)
at io.grpc.SynchronizationContext.drain(SynchronizationContext.java:101)
at io.grpc.SynchronizationContext.execute(SynchronizationContext.java:130)
at io.grpc.internal.ManagedChannelImpl$NameResolverListenerImpl.onAddresses(ManagedChannelImpl.java:1317)
at io.grpc.internal.DnsNameResolver$Resolve.resolveInternal(DnsNameResolver.java:325)
at io.grpc.internal.DnsNameResolver$Resolve.run(DnsNameResolver.java:225)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
输出:
public static void Main(string[] args)
{
string data = @"{
'timestamp': {
'month': 3,
'hour': 21,
'nanosecond': 0,
'year': 2019,
'isNull': false,
'millisecond': 0,
'value': '2019-03-02T21:22:29',
'day': 2,
'binData': 'eHcDAhYXHgAAAAA=',
'minute': 22,
'second': 29
}
}";
JObject elasticDateObject = JsonConvert.DeserializeObject<JObject>(data);
DateTime resolvedDate = DateTime.Parse(elasticDateObject["timestamp"]["value"].ToString());
Console.WriteLine(resolvedDate.ToString(@"yyyy/MM/dd hh:mm:ss tt", new System.Globalization.CultureInfo("en-US")));
}