User Tools

Site Tools


Sidebar

Privacy Policy

News

Version 2.50 is out since Jan 1st 2022


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

sample_code:digital_clock

Clock

This is a simple clock.
Here is the spk.

Clock.js
//Called when application is started.
function OnStart()
{
    //Create a layout with objects vertically centered.
    lay = app.CreateLayout( "linear", "VCenter,FillXY" ); 
    lay.SetBackColor("#ff665578")   
    //Create a text label and add it to layout.
    txtd = app.CreateText( "Digital Clock" );
    txtd.SetTextSize( 45 );
    txtd.SetMargins(0,0,0,0.03)
    lay.AddChild( txtd );
     //Create Text
  text = app.CreateText( "" );
    text.SetTextSize( 25 );
    text.SetTextColor("#ff879964")
    lay.AddChild( text );
    //Create a text label and add it to layout.
    txt = app.CreateText( "" );
    txt.SetTextSize( 32 );
    lay.AddChild( txt );
 
    //Add layout to app.    
    app.AddLayout( lay );
setInterval(Clock,1000)
}
function Clock() 
{ 
  var day =["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
 var today = new Date();
    var y = today.getFullYear()
    var h = today.getHours();
    var m = today.getMinutes();
    var s = today.getSeconds();
    var mi = today.getMilliseconds();
    var mon =today.getMonth()
 var d = today.getDay()
var mon = today.getMonth()+1
var dt = today.getDate()
text.SetText(day[d]+" "+dt+"/"+mon+"/"+y)
 
if(s<10&&m<10&&h<10){
     txt.SetText("0"+h+":"+"0"+m+":"+"0"+s)
  }
else{
 
 if(s<10&&h<10){
     txt.SetText("0"+h+":"+m+":"+"0"+s)
  }
else if(h<10&&m<10){
     txt.SetText("0"+h+":"+"0"+m+":"+s)
  }
else if(m<10&&s<10){
 
     txt.SetText(h+":"+"0"+m+":"+"0"+s)
  }
else{
if(h<10){
     txt.SetText("0"+h+":"+m+":"+s)
  }
else if(m<10){
 
     txt.SetText(h+":"+"0"+m+":"+s)
  }
 
else if(s<10){
     txt.SetText(h+":"+m+":"+"0"+s)
  }
 
else{
txt.SetText(h+":"+m+":"+s)
    }
  }
 }
}

Home»Sample Code

sample_code/digital_clock.txt · Last modified: 2017/06/14 17:13 (external edit)