c++ - 在 C++ 中传递日期

标签 c++

我需要在 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/

相关文章:

c++ - 为什么 C++ STL vector 不会超出范围

c++ - 在给定每行按钮数的情况下查找需要多少行?

c++ - std::vector 中的二进制搜索

c++ - boost::mpl::map 类型和 char 字符串

c++ - 在 C++ 中创建一个巨大的标志图

c++ - 如何为堆栈变量分配内存?

c++ - 如何在 MSVC 2015 上使用 OpenMP 获得 clang

c++ - 在 C++ 中使用命名空间的目的

c++ - G++ 编译器错误或错误代码? : "template definition of non-template"

c++ - 非托管 C++ COM 和托管 C++ .NET4 互操作