C++/CLI Code Snippet - Returns current UNIX timestamp

C++/CLI Code Snippet - Returns current UNIX timestamp

C++/CLI Code Snippet - Returns current UNIX timestamp

C++/CLI code snippet to return current UNIX timestamp. UnixTimeNow() returns current UNIX timestamp

Bookmark:

C++/CLI Code Snippet - Returns current UNIX timestamp

This C++/CLI code snippet returns current UNIX timestamp. This timestamp is a long integer containing the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.

System::Int64 UnixTimeNow()
{
    TimeSpan _TimeSpan = (DateTime::UtcNow - DateTime(1970, 1, 1, 0, 0, 0));
    return safe_cast<System::Int64>(_TimeSpan.TotalSeconds);
}


C++/CLI Keywords Used:

  • TimeSpan
  • DateTime
  • UtcNow
  • safe_cast
  • TotalSeconds

Code Snippet Information:

  • Applies To: .Net, C++/CLI, Date/Time, Timestamp, Unix Time
  • Programming Language : C++/CLI

External Resources:

Leave a comment