tags:

views:

49

answers:

1

I need to pass DateTime value in C++. (Creating a plugin for AmiBroker)

I have to pass it to AmiDate .

I have date in long variable. (seconds from midnight January 1, 1980 )

The target structure is defined as below.

// 8 byte (64 bit) date time stamp
    union AmiDate
    {
     DATE_TIME_INT Date;
     struct PackedDate PackDate;
    };

struct PackedDate {
 // lower 32 bits
 unsigned int IsFuturePad:1; // bit marking "future data"
 unsigned int Reserved:5; // reserved set to zero
 unsigned int MicroSec:10; // microseconds 0..999
 unsigned int MilliSec:10; // milliseconds 0..999
 unsigned int Second: 6;  // 0..59

 // higher 32 bits
    unsigned int Minute : 6;    // 0..59      63 is reserved as EOD marker
    unsigned int Hour : 5;      // 0..23      31 is reserved as EOD marker
    unsigned int Day : 5;       // 1..31
    unsigned int Month : 4;     // 1..12
    unsigned int Year : 12;  // 0..4095

    };

Did not find a clue.

+1  A: 

One option is to make use of the C time library ctime as:

#include <ctime>

time_t numSeconds = /* your value */;

// this structure contains the broken down components of the time.
struct tm * timeinfo;

// fill in the struct by calling localtime.
timeinfo = localtime ( &numSeconds);

Now you can extract the components from struct tm object that you just filled and use it to fill your AmiDate object.

codaddict
Also google GetDateTimeArray()
Zabba