Last active
August 29, 2015 14:03
-
-
Save thurask/28283ed6d8b71e076495 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bb.cascades 1.0 | |
Page { | |
property string dayofweek | |
property string day | |
property string month | |
property string year | |
Container { | |
Label { | |
id: datelabel | |
text: "" | |
} | |
Button { | |
id: datebutton | |
text: "Get the date" | |
onClicked: { | |
var dmy = new Date(); //Current date | |
var weekarray = new Array(); | |
weekarray[0]= "Sunday"; | |
weekarray[1] = "Monday"; | |
weekarray[2] = "Tuesday"; | |
weekarray[3] = "Wednesday"; | |
weekarray[4] = "Thursday"; | |
weekarray[5] = "Friday"; | |
weekarray[6] = "Saturday"; | |
dayofweek = weekarray[dmy.getDay()]; //getDay() returns 0-6, so we put a nice name on it | |
day = dmy.getDate(); //returns 1-31 | |
var montharray = new Array(); | |
montharray[0] = "January"; | |
montharray[1] = "February"; | |
montharray[2] = "March"; | |
montharray[3] = "April"; | |
montharray[4] = "May"; | |
montharray[5] = "June"; | |
montharray[6] = "July"; | |
montharray[7] = "August"; | |
montharray[8] = "September"; | |
montharray[9] = "October"; | |
montharray[10] = "November"; | |
montharray[11] = "December"; | |
month = montharray[dmy.getMonth()]; //getMonth() returns 0-11, so we put a nice name on it | |
year = dmy.getFullYear(); //2014 | |
datelabel.text = dayofweek + ", " + day + " " + month + " " + year; //Monday, 7 July 2014 | |
//Alternatively, dmy.toDateString() returns Mon Jul 07 2014, which is good enough for me | |
//In that case: | |
//var fulldate = dmy.toDateString(); // Mon Jul 07 2014 | |
//var datearray = fulldate.split(" "); // [Mon, Jul, 07, 2014] | |
//Set dayofweek, day, month and year from that array | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment