Convert timestampt to date/time?

Posted on
Sun Apr 08, 2018 9:30 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Convert timestampt to date/time?

Hi C4W.

Just thought I'd use this to convert a Unix timestamp to a visual date, purely for something I'm debugging in one of my own plugins - when I noticed that's not one of the options?

(Unless, there's a %code for the full timestamp but I can't find one?)

Peter

Posted on
Sun Apr 08, 2018 9:33 am
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: Convert timestampt to date/time?

Well, the date format is Python but it's just reading a string, so as long as you specify the format, in Python notation, it should covert.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Sun Apr 08, 2018 9:37 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Convert timestampt to date/time?

But that’s the problem, there is no date notation for time.time() that strftime() etc supports?

If I’d used time.strftime(%y %m %d, time.time()) when creating my plugin then I could use your plugin to convert %y %m %d to something else.

But I used time.time() in my plugin, purely for counting seconds elapsed, so I didn’t need to format it in the plugin when I stored it in a state.

Now I want to temporarily (without recoding states) see the h:m:s value of that timestamp?


Sent from my iPhone using Tapatalk Pro

Posted on
Sun Apr 08, 2018 9:52 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Convert timestampt to date/time?

Code: Select all
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
==> '2018-04-08 16:49:40'
Code: Select all
time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(time.time()))
==> '2018-04-08 15:50:19'

I am in the UK.. delta of 1 hour is due to DST

Karl
Last edited by kw123 on Sun Apr 08, 2018 9:54 am, edited 1 time in total.

Posted on
Sun Apr 08, 2018 9:54 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Convert timestampt to date/time?

I know how to do it in code, I just thought it would a) be in the DE plugin already and b) because it isn’t, be a useful suggestion.

Seems not.


Sent from my iPhone using Tapatalk Pro

Posted on
Sun Apr 08, 2018 10:36 am
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: Convert timestampt to date/time?

howartp wrote:
I know how to do it in code, I just thought it would a) be in the DE plugin already and b) because it isn’t, be a useful suggestion.

It is and I'll look to add that. DE is a mess on my end right now with so many changes so you won't see that change for a while, that's why I was trying to see if there was a way to do it with what DE already does.

I didn't understand that you were wanting to drop to a shell to do it, I thought it was in Unix format and sitting somewhere in Indigo already, then it's a matter of converting the format.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Sun Apr 08, 2018 12:41 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Convert timestampt to date/time?

Colorado4Wheeler wrote:
howartp wrote:
I know how to do it in code, I just thought it would a) be in the DE plugin already and b) because it isn’t, be a useful suggestion.

It is and I'll look to add that. DE is a mess on my end right now with so many changes so you won't see that change for a while, that's why I was trying to see if there was a way to do it with what DE already does.

I didn't understand that you were wanting to drop to a shell to do it, I thought it was in Unix format and sitting somewhere in Indigo already, then it's a matter of converting the format.

Hehe, I don't want to drop to a shell, and it is in Unix format sitting in Indigo already...

Never mind, I've sorted my plugin issue anyway - it will be good to add to DE when you get to it but no urgency.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests