Author Topic: Timestamp to readable string  (Read 1513 times)

0 Members and 1 Guest are viewing this topic.

mht

  • Jr. Member
  • **
  • Posts: 7
  • Karma: 1
    • View Profile
Timestamp to readable string
« 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?

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Timestamp to readable string
« Reply #1 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
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

  • Jr. Member
  • **
  • Posts: 7
  • Karma: 1
    • View Profile
Re: Timestamp to readable string
« Reply #2 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>

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Timestamp to readable string
« Reply #3 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.
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)