Visual Studio Development Bookmark and Share   
 index > Visual C# Express Edition > "Universal Coordinated Time" since 01/01/2000?
 

"Universal Coordinated Time" since 01/01/2000?

A C# app I'm doing needs "Universal Coordinated Time" since 01/01/2000 in seconds and in hex (4 bytes big endian). So far I have found everything else and not what I'm needing. It seems that no one else is doing this or it would be somewhere easy to find.
tfcsd  Tuesday, October 13, 2009 2:44 PM
            TimeSpan ts = DateTime.UtcNow - new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
            byte[] big = BitConverter.GetBytes((int)ts.TotalSeconds);
            Array.Reverse(big);

Hans Passant.
  • Marked As Answer bytfcsd Tuesday, October 13, 2009 3:50 PM
  •  
nobugz  Tuesday, October 13, 2009 3:25 PM
You can get the seconds since 1/1/2000 via:
DateTime now = DateTime.Now.ToUniversalTime(); // Convert to "Coordinated Universal Time"
DateTime origin = new DateTime(2000,1,1); // 1/1/2000

TimeSpan difference = now - origin;

int secondsSinceJan2000 = (int)difference.TotalSeconds; // Convert to 4 byte integer

int secondsSinceJan2000BigEndian = System.Net.IPAddress.HostToNetworkOrder(secondsSinceJan2000);

The last line uses HostToNetworkOrder to convert the int (which is a 4 byte int) to Big-Endian order.
Reed Copsey, Jr. - http://reedcopsey.com
Reed Copsey, Jr.  Tuesday, October 13, 2009 3:09 PM
            TimeSpan ts = DateTime.UtcNow - new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
            byte[] big = BitConverter.GetBytes((int)ts.TotalSeconds);
            Array.Reverse(big);

Hans Passant.
  • Marked As Answer bytfcsd Tuesday, October 13, 2009 3:50 PM
  •  
nobugz  Tuesday, October 13, 2009 3:25 PM
thanks
tfcsd  Tuesday, October 13, 2009 3:51 PM

You can use google to search for other answers

Custom Search

More Threads

• Can any one give a way
• accessing attribute of the object in the objects' arrayList
• Weird MSBuild errors
• DataGridView to XML using Dataset
• Sources for GUI-developing
• keyCollection problem
• 'Registry' does not contain a definition for 'CurrentUser'
• Search for text in any column of datatable
• Accessing my NotifyIcon from another Form
• In the column KaartID there aren't allowed null values...