converting long long to date

This is a discussion on converting long long to date within the C Programming forums, part of the General Programming Boards category; well i have a value which is a long long (5245738275906267986), at least what i gather from my internet research ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    5

    converting long long to date

    well i have a value which is a long long (5245738275906267986), at least what i gather from my internet research

    lower limit
    −9,223,372,036,854,775,808

    upper limit
    9,223,372,036,854,775,807

    the following produces unexpected output.

    long long x = 5245738275906267986;
    time_t dt = x;
    printf("dt: %s\n", ctime(&dt));

    how would i properly convert the value to time_t

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    You wouldn't. That is several thousand years into the future.

    Where are you getting this value from?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    As MK27 implied, timestamp is in seconds. So your huge number is billions of years in the future. If the value is in microseconds it's still too huge.

    At about a billion seconds is where the number would be to represent today. That's how many seconds are in 30 years starting from 1980.

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    5
    the value is a DateTime converted to an int64 value in a C# program. the C# program then sends the value to a C application where it needs to be converted to a DateTime to check the authenticity of the call, along with a few other values contained within a hashed string.

    is the issue that the value is generated within C#?

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    The issue is that "5245738275906267986" is not a valid date. If it were a number of seconds, it would be more than 166341269530 years. Is this a special Galactic calender or something?

    A C# DateTime is an object. What value from it did you convert to an int64?

    Basically someone has mangled this data.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Registered User
    Join Date
    Mar 2010
    Posts
    5
    hmmmm, maybe C# itself modifies the value.

    here is the C# code which creates the value
    long binValue = DateTime.UtcNow.ToBinary()

    here is the C# code which decodes the value
    DateTime.FromBinary(binValue);

    the portion of the code which converts the binValue to a DateTime needs to be happen in C. what is the best way to approach this conversion?

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    That number is not necessarily (not at all?) the number of ticks, as it also contains the information about Kind (according to DateTime.ToBinary Method (System) at any rate). So the question is "why does it need to happen in C, and if it does, why don't you get 'real' data out of the thing (like the number of ticks)?"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting string to unsigned long
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-15-2009, 11:37 PM
  2. error: double free or corruption
    By dsc in forum C Programming
    Replies: 3
    Last Post: 04-03-2008, 09:26 AM
  3. Help on converting date
    By knutso in forum C Programming
    Replies: 15
    Last Post: 10-14-2007, 06:00 AM
  4. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 05:59 AM
  5. Converting an 8-Byte Array into a Long Representation
    By maththeorylvr in forum C Programming
    Replies: 11
    Last Post: 06-17-2005, 03:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21