VoxCommando

General Discussion => General Discussion => Topic started by: mht on April 29, 2015, 05:13:17 PM

Title: Timestamp to readable string
Post by: mht on April 29, 2015, 05:13:17 PM
I have a timstamp (date and time) in this format: 1430337630

How do I convert this timestamp to a readable time string?
Title: Re: Timestamp to readable string
Post by: nime5ter on April 29, 2015, 05:31:51 PM
You can use the Python plugin. Simplest would be something like:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.6-->
<command id="667" name="convert time stamp" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>PY.ExecString</cmdType>
    <params>
      <param>result = time.ctime(1430337630)</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>The time is {LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>convert time stamp</phrase>
</command>

https://docs.python.org/2/library/time.html
Title: Re: Timestamp to readable string
Post by: mht on April 30, 2015, 07:27:16 AM
Tank you!

I follow your example. It didnt work at first. I found out that I had to add time library first.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.6-->
<command id="667" name="convert time stamp" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>PY.ExecString</cmdType>
    <params>
      <param>import time; result= time.ctime(1430337630)</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>The time is {LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>convert time stamp</phrase>
</command>
Title: Re: Timestamp to readable string
Post by: nime5ter on April 30, 2015, 08:39:55 AM
Sorry! Yes that was my oversight. I already had the time library loaded previously, so it worked for me.

I'm glad that you could solve the problem.