Getting Time & Date

Beginner

Okay, this one's a quickie.

DX already has a plugin to display the date or time. Just go to object Properties > Genereal > Additional Abilities and click ‘add’. You’ll be presented with this(depending on which version of DX you have):



You can choose from a display of clock hands (Analog clock 2), a plugin that makes any object move like a clock hand (Analog clock 3), a plugin that displays the date, and plugin that displays a digital clock.

In this quick tutorial I’ll show you how to make your own digital clock through scripting and in several formats, too. To learn how to make your own analog clock through scripting check out my Analog Clock tutorial here:
Link

STEP 1- Create a text object.

STEP 2- Insert this script and apply.


Sub Object_OnScriptEnter
object.Settimer 1, 1000'-Set a 1 second timer
End Sub

'-Check the time every second
Sub Object_Ontimer1
dateNtime= Now()'-Current date and time
date1= FormatDateTime(now,1)'--Full date
date2= FormatDateTime(now,2)'--Short date
date3= Day(date)'--Current day of the month
day1= WeekdayName(Weekday(Date), False)'--Full weekday
day2= WeekdayName(Weekday(Date),True)'--Abbreviated weekday
day3= Weekday(now)'--Number representing day of week
currentmonth1= MonthName(Month(now),False)'--Full month
currentmonth2= MonthName(Month(now),True)'--Abbreviated month
currentmonth3= Month(now)'--Number representing month of year
currentyear= Year(now)'--Current year
thetime= Time'--Current time
thetime2= FormatDateTime(now,3)'--Current time in 24-hour format
thehour= hour(now)'--Current hour in 24-hour format
theminute= Minute(now)'--Current minute
thesecond= Second(now)'--Current second

object.text = dateNtime
End Sub




Now change object.text= dateNtime to object.text= date1, and apply. Try out all the different variables and see the results.


STEP 3- Information Combinations

Create a 2nd text object.

Go back to the 1st object and insert this line right under object.text = dateNtime:

Desktopx.Object("object2").text = "Today is " & day1 _
& ". The year is " & currentyear & ", " & currentmonth1 & " " & date3

Or try this one:

Desktopx.Object(“object2”).text = “It’s a wonderful “ & day1 & “ morning!”

How about this one:

Desktopx.Object("object2").text = thesecond & " seconds, " _
& theminute & " minute(s) and " & thehour & " hour(s) have passed on this " & date1

Go ahead, try some more combinations!

Now, you can see how easy it is to make a digital clock via scripting. That’s it! Class dismissed, please leave a comment on your way out. Thanks.




6,561 views 3 replies
Reply #1 Top
nice. now to give it a try.
Reply #2 Top
I love these mini tutorials and the wonderful scripts you provide sViz. I'm wearing a doggy smile that's for sure.  
Reply #3 Top
This is really great! I now have at my fingertips several lessons on using the programs that come with object desktop. I am in heaven!!

sprinkle