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

  • Home
  • SEARCH
  • 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 6105631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:59:30+00:00 2026-05-23T13:59:30+00:00

While profiling my application I found that DateTime.FromFileTime(long fileTime) is slow. Does anyone know

  • 0

While profiling my application I found that DateTime.FromFileTime(long fileTime) is slow.

Does anyone know of a fast managed equivalent or the windows file time format?

[EDIT]
I was able to get some speed gains doing the following:

 var timeStr = FastTimeStringFormat(new DateTime(fileTime + 0x701ce1722770000L, DateTimeKind.Utc).ToLocalTime()); // + 0x701ce1722770000L is the offset needed to convert to UTC DateTime

For more speed but less safety (no intra-day daylight savings time checks), you can cache the ToLocalTime offset (long) and spare the more expensive expensive ToLocalTime() call.

On App Start:

long fileTimeOffset = DateTime.Today.Subtract(DateTime.Today.ToUniversalTime()).Ticks + 0x701ce1722770000L;

Then in your critical path:

var timeStr = FastTimeStringFormat(new DateTime(fileTime + fileTimeOffset));

As it turned out ToString is very expensive and the following is faster.

    public static unsafe string FastTimeStringFormat(DateTime time)
    {
        // modified version from the following post:
        // http://geekswithblogs.net/akraus1/archive/2006/04/23/76146.aspx
        // this one is also more accurate because of true divide by 10, beware of less accurate versions that do not use division


        char* FixedCharArray = stackalloc char[13];

        int hour = time.Hour; // Cache property values

        int minute = time.Minute;

        int second = time.Second;

        int ms = time.Millisecond;

        // hour

        FixedCharArray[0] = (Char)('0' + hour / 10);

        FixedCharArray[1] = (Char)('0' + hour % 10);

        FixedCharArray[2] = ':';
        // minute

        FixedCharArray[3] = (Char)('0' + minute / 10);

        FixedCharArray[4] = (Char)('0' + minute % 10);

        FixedCharArray[5] = ':';
        // seconds

        FixedCharArray[6] = (Char)('0' + second / 10);

        FixedCharArray[7] = (Char)('0' + second % 10);

        FixedCharArray[8] = '.';
        // miliseconds

        FixedCharArray[9] = (Char)('0' + ms / 100);

        FixedCharArray[10] = (Char)('0' + ms % 100 / 10);

        FixedCharArray[11] = (Char)('0' + ms % 10);

        return new String(FixedCharArray);

    }
  • 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. Editorial Team
    Editorial Team
    2026-05-23T13:59:31+00:00Added an answer on May 23, 2026 at 1:59 pm

    DateTime.FromFileTime() is implemented in managed code, there are no P/Invoke calls involved.

    The performance hit you’re experiencing might come from the conversion to local time that is performed internally. Try using DateTime.FromFileTimeUtc() instead, if at all possible.

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

Sidebar

Related Questions

while profiling a java application that calculates hierarchical clustering of thousands of elements I
I am using unsigned long to collect performance data while profiling an application as
While profiling my Python's application, I've discovered that len() seems to be a very
While profiling an application I noticed that RandomAccessFile.writeLong was taking a lot of time.
I am running into the following issue while profiling an application under VC6. When
while profiling NHibernate with NHProf I noticed that a lot of time is spend
I've got this webapp that needs some memory tuning. While I'm already profiling the
I am now profiling an application, who does a lot of disk I/O. At
I am running some profiling tests, and usleep is an useful function. But while
While the C# spec does include a pre-processor and basic directives (#define, #if, etc),

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.