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

标签 date types thrift

我正在使用 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/

    相关文章:

    PHP 用法语打印月份?

    date - 为什么我需要在Grails中解析日期?

    perl - 如何使用 Perl 的 Net::Cassandra::Easy 检索所有匹配行的所有列?

    java - 将 groupBy rdd 结果保存回 HDFS

    excel - 动态生成数据验证列表的年份数组Excel VBA

    Java - 格式化日期打印

    haskell - 假设单位类型相同是否安全?

    scala - 关于 scala 类型推断的编译错误

    scala - 相同类型的 Apache Spark 类型不匹配(字符串)

    cassandra - org.apache.thrift.transport.TTransportException : Cannot read. 远程端已关闭