Convert timestampt to date/time?

howartp
Posts: 4559
Joined: Thu Jan 09, 2014 4:43 pm
Location: West Yorkshire, UK

Convert timestampt to date/time?

Post by howartp »

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
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

Re: Convert timestampt to date/time?

Post by Colorado4Wheeler »

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
howartp
Posts: 4559
Joined: Thu Jan 09, 2014 4:43 pm
Location: West Yorkshire, UK

Re: Convert timestampt to date/time?

Post by howartp »

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
User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

Re: Convert timestampt to date/time?

Post by kw123 »

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.
howartp
Posts: 4559
Joined: Thu Jan 09, 2014 4:43 pm
Location: West Yorkshire, UK

Re: Convert timestampt to date/time?

Post by howartp »

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
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

Re: Convert timestampt to date/time?

Post by Colorado4Wheeler »

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
howartp
Posts: 4559
Joined: Thu Jan 09, 2014 4:43 pm
Location: West Yorkshire, UK

Re: Convert timestampt to date/time?

Post by howartp »

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.
Post Reply

Return to “Device Extensions Plugin”