Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i convert the simple system 24 hour format to Timestamp

I want to retrieve slack messages pasted between 4 pm to 4:30 pm daily from a certain slack channel. Slack provides a Web API for a channel as https://api.slack.com/methods/channels.history

The above API provides 2 attributes as latest & oldest , this means i can extract the messages between these 2 timestamps. But my problem is that these are time stamp and i have to make a request for timestamp as:

latest  1459750060.000002   #end

oldest  1459750060.000002   #start

I want to pass the 2 data as simple time objects i.e

latest_simple = 0430pm     #end
oldest_simple = 0400pm     #start
latest_real_format = convert_to_timestamp(latest_simple)
oldest_real_format = convert_to_timestamp(oldest_simple ) 

so if somehow i am able to get the timestamp , then i will easily be able to send make request to API as

payload = {'token': 'XXXXXXXx', 'channel': 'C0L8MGLMN' , 'latest': latest_real_format , 'oldest':oldest_real_format  }
r = requests.get('https://slack.com/api/channels.history', params=payload)

How can i do this ?

like image 910
Nishant Singh Avatar asked Apr 04 '16 11:04

Nishant Singh


People also ask

How do I use 24 hour format in datetime?

Two 'H' in HH is for 24-hour format. Description as to why this works would be useful. Such as HH for 24 hour format as hh for 12 hour.

How do I convert 12 hour format to 24 hour format in SQL?

In SQL Server 2012, we can use Format function to have suitable date time format. Use capital letter 'HH:mm:ss' for 24 hour date time format.

How do I convert my Android 24 hour clock to 12 hour time?

You can return to 12-hour time by tapping Use 24-Hour Format again. Tap Select Date Format. Tap one of the three format options to change the date format. If you don't want to change the date format, tap Cancel.


1 Answers

The timestamps are UNIX epoch in milliseconds. Assuming you are using Python here are examples how to convert it to datetime and back. As already mentioned in the comments you need to include the date in your "simple timestamp" for which you want to retrieve the messages for.

  • From date/time to timestamp: Convert string date to timestamp in Python

  • From timestamp to date/timp: Convert microsecond timestamp to datetime in Python

like image 56
Erik Kalkoken Avatar answered Sep 28 '22 05:09

Erik Kalkoken