how do i make time and date like this???





does anyone know how to make time and date like this with desktop X? if do, can u like give me a simple guide or something...or if anyone has time, can they make me one..not really pro with computers...thanks..

BTW, THE PICTURS ABOVE IS FROM A MEMBER NAMED "THREI" so THREI if u don't like that i used ur picture for example u can tell me to take it off!! or if ur kind enough to help me make one :D
6,391 views 24 replies
Reply #1 Top
Just to be clear, if you are planning on releasing or distributing this object you are making you would have to get permission from the original artist first.

If it’s for your own personal use then read on.

This is what I figured on my own. It could be a specific type of font that makes certain letters lower than others (wild guess). But, for sure if you want it to look exactly like that you would need that font.

In the second picture it looks like there could be 3 different objects

1.Date
2.Weekday
3.Month

Each of them would be positioned higher or lower and then grouped.
You would go to the ‘states’ tab in the properties and change the object from ‘image’ to ‘text’

Insert the scripts below to their respective objects.

The Date object:

Dim d

d= day(date)
Object.text= d

------------------------------
The Weekday object:

Dim dy

dy= WeekdayName(Weekday(Date),true) ‘---This will make the weekday appear abbreviated. For the full name remove ‘,true’ from the parenthesis.
Object.text = dy
-------------------------------

The Month object:

Dim m

m = month(date)

Select Case m’—The following checks what month it is and changes the object text accordingly
Case 1
object.text= “Jan”
case 2
object.text= “Feb”
case 3
object.text= “Mar”
case 4
object.text= “Apr”
case 5
object.text= “May”
case 6
object.text= “Jun”
case 7
object.text= “Jul”
case 8
object.text= “Aug”
case 9
object.text= “Sept”
case 10
object.text= “Oct”
case 11
object.text= “Nov”
case 12
object.text= “Dec”

End Select

----------------------

Don't have much time now so I’ll get back to you later on the time object.


For more info on vbscript functions like weekday, date, etc, go to W3Schools ----


[link="http://www.w3schools.com/vbscript/vbscript_ref_functions.asp"]http://www.w3schools.com/vbscript/vbscript_ref_functions.asp">Link


Hope this helps.
Reply #2 Top
Excellent. No idea why this didn't occur to me but, a lot easier on resources than using the plugin. Great.

PS. Also, a good source of information is to download Microsoft's WSH Help File which includes both vbs & jscript references as well. Using search you will get an abundant amount of date/time example codes.
Reply #3 Top
Just to add my 2 cents..

You need to add in some timers to update the date ever few mins, and the time every second (if you want seconds).

There are lots of tuts out there on timers.

Enjoy
Reply #4 Top
Good point. Actually there's a simple timer example in the DX Manual Scripting Intro Link
Reply #5 Top
You’re right about the timers, RomanDA. I forgot about that! The script needs to check what day/time it is at intervals.


Here is what the Date object script would look like with a 10 second timer added:

Sub Object_OnScriptEnter
object.SetTimer 1, 10000 '---(a ten second timer starts as soon as the object loads up)
End Sub

Sub object_ontimer1
Dim d

d= day(date)
Object.text= d

End Sub



Just do the same for the other objects as well.

Okay, now for the Time object.

When I looked for the vbscript code for time I found that it always displays the seconds and the AM/PM with it. That’s not how the 1st picture appears. So it seems I had to splice everything up. In total there are 3 text objects. Again, they would be positioned and grouped.

1. The hour (plus the colon)
2. The minutes
3. am/pm


The Hour object (* since the hour function returns the hours from 0 – 23 instead of 1 – 12 I had to put in the hours myself using Select Case)

Sub Object_onscriptenter
object.SetTimer 1, 1000'---a one-second timer starts as soon as the object loads up
End Sub

Sub object_ontimer1
Dim h
h = hour(now)

Select Case h '-the following checks the hours (0-23) and changes the text to the hours 1-12 accordingly
Case 0
Object.text= "12:"
Case 1
object.text= "1:"
Case 2
object.text= "2:"
Case 3
object.text= "3:"
Case 4
object.text= "4:"
Case 5
object.text= "5:"
Case 6
object.text= "6:"
Case 7
object.text= "7:"
Case 8
object.text= "8:"
Case 9
object.text= "9:"
Case 10
object.text= "10:"
Case 11
object.text= "11:"
Case 12
object.text= "12:"
Case 13
object.text= "1:"
Case 14
object.text= "2:"
Case 15
object.text= "3:"
Case 16
object.text= "4:"
Case 17
object.text= "5:"
Case 18
object.text= "6:"
Case 19
object.text= "7:"
Case 20
object.text= "8:"
Case 21
object.text= "9:"
Case 22
object.text= "10:"
Case 23
object.text= "11:"


End Select
End Sub

----------------------
The Minute object

Sub Object_onscriptenter
object.SetTimer 1, 1000
End Sub

Sub object_ontimer1
Dim m
m = minute(now)

object.text = m

End Sub

---------------------------
The AM/PM object

Sub Object_onscriptenter
object.SetTimer 1, 1000
End Sub

Sub object_ontimer1'---the following checks the hours (0 – 23). Anything less than 11 is AM. Anything greater than 11 is PM
Dim h
h = hour(now)

If h <= 11 Then
object.text = "AM "
ElseIf h >11 Then
Object.text= "PM"
End If

End Sub





That’s all there is to that!
Reply #6 Top
Instead of doing that long select statement to get the abbreviated monthname, you could just do this:

Dim m
m = month(date)
MonthName(m, True)

(ref: http://www.w3schools.com/vbscript/func_monthname.asp)



And instead of the select statement to get AM and PM hours you can do:

Dim h
h = hour(FormatDateTime(now, 3)) & ":"

FormatDateTime(now, 3) return the current time in AM PM format.
(ref: http://www.w3schools.com/vbscript/func_formatdatetime.asp)

Reply #7 Top
Thanks, thomassen! I couldn't figure that out. That's so much easier!


So now the month script looks like this:

Sub Object_onscriptenter
object.SetTimer 1, 10000
End Sub

Sub object_ontimer1
Dim m
m = month(date)
mo= MonthName (m, True)

object.text= mo


End Sub


------------
And the Hour script looks like this:

Sub Object_onscriptenter
object.SetTimer 1, 1000
End Sub

Sub object_ontimer1
Dim h
h = hour (FormatDateTime(now, 3))& ":"

object.text = h

End Sub



I guess we solved this question! Thanks to all the forumers who stopped by to help. (Now, I wonder if supr4 is even still making this object?)
Reply #8 Top
One other thing. The time now is 3 minutes past the hour and the minute object only displays '3' instead of '03'.

Any ideas?
Reply #9 Top
Odd that VBScript doesn't have a function to pad a string to a certain lenght. But this should work for what we want here at least.
Reply #10 Top
How odd. The forum ate my code....

Let give it another go:


Sub Object_onscriptenter
object.SetTimer 1, 1000
End Sub

Sub object_ontimer1
Dim m
m = minute(now)
If Len(m) = 1 Then m = "0" & m
object.text = m

End Sub
Reply #11 Top
Simple and effective. It worked! Thanks again.  

But it is now after noon and the hour object still displays in the 23 hour format. I'm not sure what I did wrong. I used exactly the code posted above.
Reply #12 Top
hm.... it seem that VBscript will display time depending to what the computer's locale settings are set to. And there doesn't seem to be any prebuildt functions to spesify what format you want. So it seems that manual tricksery has to be done.

Dim h
h = Hour(Now())
If h > 12 Then h = h - 12
Object.Text = h & ":"
Reply #13 Top
Genius! Thanks a lot thomassen! You sure know your way around scripting. 
Reply #14 Top
Or why not, for the time just have:

Sub Object_OnTimer1
Object.Text = FormatDateTime(Time(),4)
End Sub

This will produce an output like: "11:52"
Reply #15 Top
Well that just simplified everything-- reducing the time to just 2 objects. Good catch, Cyberium. I certainly have learned alot from this thread.

Question: Is there any way to set the time/date to somewhere else in the world-- a specific country? I kinda had an idea for a widget.....


UPDATE: It is now after noon and it is back to the 23 hour time format....
Reply #16 Top
That's because when using 4 as argument for the FormatDateTime it will "Display a time using the 24-hour format: hh:mm" ref: http://www.w3schools.com/vbscript/func_formatdatetime.asp


As for returning a different country, you have to find the timezone and then adjust that according to the time zone difference. Use DateAdd to add the number of hours you need. ref: http://www.w3schools.com/vbscript/func_dateadd.asp


To further comlicate it, it seems that there is no function in VBScript that returns the time for a standard timezone such as GTM. So you have to find out what time zone you are in and then calculate the difference accoring to that.
Reply #17 Top
Something to look into... maybe WMI Services can help? It seems its the place to go to mess with system settings (apart from setting IP addresses!). I had an idea for a Screen Resolution changer... Ku... Back in a Jiffy!
Reply #18 Top
Okismokes! It is possible to change the screen Resolution via WMI Services! Woo! Sharing this info it can be found in the Win32_VideoConfiguration Class, you set the HorizontalResolution (i.e. 1024) and the VerticalResolution (i.e. 768).. Learning is fun!
Reply #19 Top
Well I suppose if you KNOW the amount of hours to add for each Zone, why not create a Drop-Down/Combobox list of the different TimeZones and just add hours & day depending which ones is selected? Say if you're currently GMT time and you need to shift to a U.S time zone then just add the relevant hours to the time
Reply #20 Top
Thanks for the tips you guys. I’m already trying to work out the script for the world clock.

I came across this problem (*The math is according to my time for now.):

t= time
desktopx.Object("gmt").text= "Greenwich Time " &(DateAdd("h",8,(t)))
desktopx.Object("utc+1").text= "UTC+1 " &(DateAdd("h",9,(t)))


The 2nd line returns the time : 11:00:00 pm
The 3rd line returns: 12/31/1899 12:00:00 am

Any thoughts on why the 3rd line returns an incorrect date along with the time?


Also: I'll be creating another thread as soon as the forums start working. (since I've unintentionally taken this one off-topic)
Reply #21 Top
I can not seem to reproduce the effect you are seeing though. Have you tried formatting the time with FormatDateTime function?

One thing: You don't need to wrap everything in brackets. You can use desktopx.Object("gmt").text = "Greenwich Time " & DateAdd("h",8,t)

Another thing: I'd recomment that you add a space behind the & symbol as it's used to define hex numbers.
Reply #22 Top
I've changed everything you mentioned. I still get the same problem. It only happens when the times are on different days (e.g. Sunday my time-- Monday GMT).
Reply #23 Top
FormatDateTime didn't work either? Like this:

t= time
desktopx.Object("gmt").text = "Greenwich Time " & FormatDateTime(DateAdd("h",8,t), 3)
desktopx.Object("utc+1").text = "UTC+1 " & FormatDateTime(DateAdd("h",9,t), 3)
Reply #24 Top
That did it! I put the FormatDateTime with t=time before. Thank you very much! You're a great help.