我正在使用 apache thrift 开发服务我需要定义时间段。日期很重要( YYYY-mm-dd
),时间应该完全省略( HH:ii:ss
)。我找不到任何特定的日期/日期时间节俭数据类型,所以我在考虑两种方法:
int year,
int month,
int day,
int timestamp
是否有一种常见的节俭方法来表示日期(时间)类型?
最佳答案
我认为 Thrift 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;
}
字符串更易于使用 JODA Operations
- 编辑 -
我不知道您打算存储什么时间戳。例如,如果您想计算发生了事务的当前实例并将其存储到该 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);
关于date - 如何在 apache thrift 中表示日期类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15603505/