timestamp - 如何将简单的24小时制转换为时间戳

标签 timestamp slack-api slack

我想从某个松弛 channel 检索每天下午4点至4:30 pm粘贴的松弛消息。
Slack为 channel 提供了一个Web API,即https://api.slack.com/methods/channels.history

上面的API提供了2个属性,分别是latestoldest,这意味着我可以提取这两个时间戳之间的消息。但是我的问题是这些是时间戳,我必须要求时间戳为:

latest  1459750060.000002   #end

oldest  1459750060.000002   #start

我想将2个数据作为简单的时间对象传递,即
latest_simple = 0430pm     #end
oldest_simple = 0400pm     #start
latest_real_format = convert_to_timestamp(latest_simple)
oldest_real_format = convert_to_timestamp(oldest_simple ) 

因此,如果我能够以某种方式获取时间戳,那么我将能够轻松地将make请求发送给API
payload = {'token': 'XXXXXXXx', 'channel': 'C0L8MGLMN' , 'latest': latest_real_format , 'oldest':oldest_real_format  }
r = requests.get('https://slack.com/api/channels.history', params=payload)

我怎样才能做到这一点 ?

最佳答案

时间戳是UNIX纪元,以毫秒为单位。假设您使用的是Python,下面是示例如何将其转换为日期时间和返回日期的示例。正如评论中已经提到的那样,您需要在“简单时间戳记”中包括要为其检索消息的日期。

  • 从日期/时间到时间戳记:
    Convert string date to timestamp in Python
  • 从时间戳记到日期/提示:
    Convert microsecond timestamp to datetime in Python
  • 关于timestamp - 如何将简单的24小时制转换为时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36401391/

    相关文章:

    apache-kafka - 在Kafka中如何根据生产时间获得确切的偏移量

    python - 在Python中解析时间戳

    postgresql - 1892 年之前的 postgresql 中带有时区错误的时间戳

    python - 如何在 slack.client 中提及用户

    python - 从Python API找出Slack消息的时间戳

    amazon-web-services - 确认 Slack Webhook 的 AWS SNS 主题订阅

    java - Android - 使用游标适配器在 ListView 中格式化时间戳

    slack - Hubot 与 Slack 的集成

    slack - 在 Slack API 中,im、mpim 和 group 有什么区别?

    slack-api - 松弛api rtm.start missing_scope所需的客户端