News:

Would you like to say "Thanks!" for extra support or new features that we provided? Donations are gratefully accepted.

Main Menu

Timestamp to readable string

Started by mht, April 29, 2015, 05:13:17 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

mht

I have a timstamp (date and time) in this format: 1430337630

How do I convert this timestamp to a readable time string?

nime5ter

You can use the Python plugin. Simplest would be something like:

<?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
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

mht

Tank you!

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

<?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>

nime5ter

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.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)