Author Topic: Display current time  (Read 6974 times)

kent79

  • Hero Member
  • *****
  • Posts: 842
    • View Profile
Display current time
« on: February 07, 2016, 07:39:09 PM »
Hi

I would like to add current time function in theme. date() is working, but don't know full script of interval update in background. Please help me., Thanks.

date().hour
date().min

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: Display current time
« Reply #1 on: February 13, 2016, 01:40:10 PM »
Code: [Select]
local dt = fe.add_text( "", 0, 0, fe.layout.width, 30 );
fe.add_ticks_callback( this, "update_clock" );
function update_clock( ttime )
{
local now = date();
dt.msg = now.hour + ":" + now.min + ":" + now.sec;
}

Try here for more info:
https://electricimp.com/docs/squirrel/system/date/

kent79

  • Hero Member
  • *****
  • Posts: 842
    • View Profile
Re: Display current time
« Reply #2 on: February 13, 2016, 07:17:15 PM »
Hi liquid8d,

it works, do you know how to change display format to (h:mm) like as below? Thanks.

example 1: 13:5 to 13:05
example 2: 1:9 to 1:09
 
« Last Edit: February 20, 2016, 11:44:51 AM by kent79 »

kent79

  • Hero Member
  • *****
  • Posts: 842
    • View Profile
Re: Display current time
« Reply #3 on: February 22, 2016, 10:55:12 PM »
Not support change to date format in current AM right?  Please help me to confirm. Thanks.

raygun

  • Administrator
  • Sr. Member
  • *****
  • Posts: 393
    • View Profile
Re: Display current time
« Reply #4 on: February 23, 2016, 06:39:31 AM »
Hey there, you can use the "format" function: http://www.squirrel-lang.org/doc/sqstdlib3.html#d0e2180

So something like: 
Code: [Select]
format("%02d", now.min ) instead of just
Code: [Select]
now.min should do what you want

kent79

  • Hero Member
  • *****
  • Posts: 842
    • View Profile
Re: Display current time
« Reply #5 on: February 23, 2016, 07:22:13 AM »
Hey there, you can use the "format" function: http://www.squirrel-lang.org/doc/sqstdlib3.html#d0e2180

So something like: 
Code: [Select]
format("%02d", now.min ) instead of just
Code: [Select]
now.min should do what you want

Thank you raygun  :)