Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 116153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:07:58+00:00 2026-05-11T03:07:58+00:00

I have a legacy C++-based application that timestamps incoming network traffic using the CRT

  • 0

I have a legacy C++-based application that timestamps incoming network traffic using the CRT _ftime() function. The _ftime() function returns a _timeb structure, which has a 32-bit and a 64-bit implementation. We are using the 32-bit implementation, which looks like this:

struct _timeb {     long time;              // 4 bytes     unsigned short millitm; // 2 bytes     short timezone;         // 2 bytes     short dstflag;          // 2 bytes }; 

From the MSDN documentation, here is how each field is interpreted:

  • dstflag – nonzero if daylight savings time is currently in effect for the local time zone (see _tzset for an explanation of how daylight savings time is determined.)
  • millitm – fraction of a second in milliseconds
  • time – time in seconds since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC).
  • timezone – difference in minutes, moving westward, between UTC and local time. The value of timezone is set from the value of the global variable _timezone (see _tzset).

I am re-working the portion of the code that does the timestamping to use C# in .NET 3.5. Timestamps are now generated using the System.DateTime structure, but I still need to convert them back to the _timeb structure so the legacy C++ code can operate on them. Here is how I am doing that in my managed C++ bridge library:

DateTime dateTime = DateTime::UtcNow; DateTime baseTime(1970, 1, 1, 0, 0, 0, DateTimeKind::Utc); TimeSpan delta = dateTime - baseTime;  _timeb timestamp; timestamp.time     = delta.TotalSeconds; timestamp.millitm  = dateTime.Millisecond; timestamp.dstflag  = TimeZoneInfo::Local->IsDaylightSavingTime(dateTime) ? 1 : 0; timestamp.timezone = TimeZoneInfo::Local->BaseUtcOffset.TotalMinutes * -1; 

From what I can tell, this appears to reconstruct the _timeb structure as if I had called _ftime() directly, and that’s good. The thing is, timestamps are a critical piece of our application, so this has to be right.

My question is two-fold.

  1. Is my algorithm flawed somehow? Does anyone see anything obvious that I’ve missed? Are there boundary conditions where this won’t work right?
  2. Is there a better way to do the conversion? Does .NET have a way to do this in a more straightforward manner?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:07:59+00:00Added an answer on May 11, 2026 at 3:07 am

    You’re aware of the Y2K38 problem? I assume you checked the sign of .timezone. Avoid the cleverness of using dateTime.Millisecond, that just confuses the next guy. Looks good otherwise.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some legacy application logic that sends files to an attached printer using
We have a legacy web application (not Spring based) and are looking for best
I have several instances where that a section of legacy sql statements is based
I have a legacy C++ module that offers encryption/decryption using the openssl library (DES
I have a legacy application that looks for files in a directory. It does
I am working with a legacy application that stored passwords in plaintext. I have
I have a legacy application that generates VRML 1.0 files. I'd like to build
Let's say I have a legacy application that, for various reasons, previous developers decided
I have a need to migrate a legacy, desktop based, single user, accounting application
I have written java application that makes socket connections with a legacy system. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.