如何在apache thrift中表示日期类型

duc*_*cin 5 types date thrift

我正在使用apache thrift开发一个服务,我需要定义一段时间.日期很重要(YYYY-mm-dd),时间应该完全省略(HH:ii:ss).我找不到任何具体的日期/日期时间节俭数据类型,所以我在考虑两种方法:

  1. 更复杂

    int year,
    int month,
    int day,
    
    Run Code Online (Sandbox Code Playgroud)
  2. 不太复杂,但包括我不需要的时间部分.

    int timestamp
    
    Run Code Online (Sandbox Code Playgroud)

是否有一种常见的节俭方法来表示日期(时间)类型?

Ven*_*nki 5

我不认为Thrift IDL上有日期表示.我们在项目中使用这种表示法.

typedef string Timestamp
Run Code Online (Sandbox Code Playgroud)

然后在需要时间戳使用的后续模型上使用该表示法

struct blah{

    /**
    * TODO:list what notation this dateTime represents. eg ISO-8601
    * or if its in the format like YYYY-mm-DD you mentioned.
    */
    1:Timestamp dateTime;

    }
Run Code Online (Sandbox Code Playgroud)

String使得JODA操作更容易使用

- 编辑 -

我不知道你打算存储什么时间戳.例如,如果要计算当前实例已发生事务并将其存储到该thrift对象中,则可以使用Joda执行此操作.

    String timestamp = new DateTime().toString("YYYY-MM-dd"); //2013-03-26 This will be string value generated. It will convert the current time to format you seek to output.
    //Use the generated thrift object.
    Blah newblah = new Blah();
    blah.setDateTime(timestamp);
Run Code Online (Sandbox Code Playgroud)