Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert Java to C # time

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to convert Java and C# time". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to convert Java and C# time".

In Java, you can get the long form of the current time with System.currentTimeMillis (), which is marked by the number of milliseconds from January 1, 1970 to the current millisecond. Web Service is written in Java. Convert this long data into timestamp and then store it in MySQL, so you can pass this value directly by calling our Web Service.

But the way to calculate time under .NET is different, it is the unit of calculation is Ticks, here you need to do a C # time conversion. Here's what the Ticks,msdn says:

A single tick represents one hundred nanoseconds or one ten-millionth of a second. The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001.

It is 1/10000000 seconds from midnight on January 1 to the specified time, which is 1/10000 milliseconds for comparison with Java.

(System.DateTime.UtcNow.Ticks-new DateTime (1970, 1, 1, 0, 0, 0) .Ticks) / 10000

If you want to get the same result as System.currentTimeMillis () in Java, you can convert Java to C # and write it as above, or you can write it like this:

TimeSpan ts=new TimeSpan (System.DateTime.UtcNow.Ticks-new DateTime (1970, 1, 1, 0, 0, 0) .Ticks); (long) ts.TotalMilliseconds

It should be noted that System.DateTime.UtcNow is used here instead of System.DateTime.Now, because we are in the East eighth District, if we use the latter form, we will find that the time will be 8 hours less than expected. The time conversion between Java and C # is completely realized here.

Thank you for your reading, the above is the content of "how to convert Java and C # time". After the study of this article, I believe you have a deeper understanding of how to convert Java and C # time, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report