我需要在 C++ 中传递 DateTime 值。 (为 AmiBroker 创建插件)
我必须将它传递给 AmiDate
。
我在 long 变量中有日期。 (从 1980 年 1 月 1 日午夜算起的秒数)
目标结构定义如下。
// 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
};
没有找到线索。
最佳答案
一个选择是使用 C 时间库 ctime
作为:
#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);
现在您可以从 struct tm
中提取组件您刚刚填充的对象并使用它来填充您的 AmiDate
对象。
关于c++ - 在 C++ 中传递日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3947885/