简体   繁体   中英

how use ToFileTime in C# in android?

can I use ToFileTime for date-time in C# for Java(Android) project? my project connects to a server and the server gets time from me by ToFileTime format.

in C#

  DateTime testdate1 = new DateTime(2000, 10, 11);
  Console.WriteLine(testdate1.ToFileTime());

  show -> 126156834000000000

Internally a DateTime stores the Ticks that happened since the begin of the UnixEpoch. Every other property and the string output are just an interpretation of that value.

"126156834000000000" looks very much like a tick value (as DateTime retreival lacks the precision to fill in those later digits). And ToFileTime() does indeed return the tick value.

Maybe you wanted the result of testdate1.ToString() ? But even that might be a bad idea.

I got 3 rules for working with Numbers and in particular Datetime:

  1. Always Store, Retreive and Transmit the UTC value. And hope you do not have to deal with Timezones manually in your application
  2. Never Store, Retreive or Transmit them as String. String is terrible for processing. The only thing worse is Binary.
  3. If you can not follow Rule 2, make sure you pick a fixed String Enconding and Culture to be used at all Endpoints. Stuff like XML & JSON take care of that for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM