Date 如何在apache thrift中表示日期类型
我正在使用开发一个服务,我需要定义时间段。日期是重要的(Date 如何在apache thrift中表示日期类型,date,types,thrift,Date,Types,Thrift,我正在使用开发一个服务,我需要定义时间段。日期是重要的(YYYY-mm-dd),时间应该完全省略(HH:ii:ss)。我找不到任何特定的date/datetime节俭数据类型,因此我考虑两种方法: 更复杂 int year, int month, int day, 不太复杂,但包括我不需要的时间部分 int timestamp 是否有一种常用的节俭方法来表示日期(时间)类型?我不知道某些特定的格式偏好。我通常使用十进制编码的日期表示法,因为它非常紧凑且易于阅读,如下所示:20130325
YYYY-mm-dd
),时间应该完全省略(HH:ii:ss
)。我找不到任何特定的date/datetime节俭数据类型,因此我考虑两种方法:
int year,
int month,
int day,
int timestamp
是否有一种常用的节俭方法来表示日期(时间)类型?我不知道某些特定的格式偏好。我通常使用十进制编码的日期表示法,因为它非常紧凑且易于阅读,如下所示:
20130325
我认为在节俭IDL上没有日期表示法。我们在项目中使用这个符号
typedef string Timestamp
然后在后续模型上使用该符号,该模型需要这样的时间戳用法
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;
}
字符串使它更容易使用
--编辑--
我不知道你打算存储什么时间戳。例如,如果您想计算当前实例中已发生的事务并将其存储到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);
您可以创建一个结构来表示您的节俭日期:
struct ThriftDate {
1: i32 year;
2: i32 month;
3: i32 day;
}
嗯,我喜欢这种表现。只是为了确定-是整数还是字符串?@tkoomzaaskz原因的整数<代码>i32节俭数据类型。没有听说过JODA,但它似乎很有前途。因此,我只通过thrift传递一个字符串,然后使用JODA库处理它?我已经编辑了答案,您可以这样做来存储时间戳。我必须亲自尝试,但这个JODA似乎提供了thrift中缺少的功能,谢谢!