Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change days 1

Status
Not open for further replies.

hendrikbez

Technical User
Nov 3, 2003
54
ZA
I have the following code, but I want to change the days e.g. "Friday = Vrydag" and the months e.g "October = Oktober". I want to know how I can change the language.

Here is my code

Imports System.Globalization
Imports System.Threading

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick

Dim dt As DateTime = DateTime.Now
Dim myformat() As String = {"dddd dd MMMM yyyy"}
Dim mydate As String
Dim I As Integer
Thread.CurrentThread.CurrentCulture = New CultureInfo("af-ZA")
lblDatum.Text = dt.ToString(myformat(0), DateTimeFormatInfo.InvariantInfo)
Dim dt1 As DateTime = DateTime.Now
Dim myformat1() As String = {"HH : MM : sss"}
Dim mydate1 As String
Dim J As Integer
lbltyd.Text = dt1.ToString(myformat1(0), DateTimeFormatInfo.InvariantInfo)
End Sub



Thanks
 
Simple solution: you have to change DateTimeFormatInfo.InvariantInfo to DateTimeFormatInfo.CurrentInfo.

That's all there's to it ;)

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
Ruffnekk

Hope you can help me again, everything is working, but now my time does mot diplay wat it should, is shows 11:10:40 and when it comes to 59 seconds, it starts again but still display 11:10.00 the minutes is not moving on.

Here is my code

Private Sub Timer2_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick

Dim dtdate As DateTime = DateTime.Now
Dim myformat() As String = {"dddd dd MMMM yyyy"}
Dim mydate As String
Thread.CurrentThread.CurrentCulture = New CultureInfo("af-ZA")
Txtdatum.Text = dtdate.ToString(myformat(0), DateTimeFormatInfo.CurrentInfo)

Dim ihour As Integer
If ihour < 12 Then
txtgroet.Text = "Goeie more, Jesus Leef!"
ElseIf ihour < 17 Then
txtgroet.Text = "Goeie middag, Leef jy vir Jesus!"
Else
txtgroet.Text = "Good aand, Jesus kom weer!"
End If

Dim dttime As DateTime = DateTime.Now
Dim myformat1() As String = {"HH : MM : ss"}
Dim mydate1 As String
Txttyd.Text = dttime.ToString(myformat1(0), DateTimeFormatInfo.InvariantInfo)

End Sub




Timer2_Tick shows in properties interval =1000

Thanks
Hendrik
 
There are quit some flaws about your code. I hope you don't mind me correcting them.

Code:
  Private Sub Timer2_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick

    Dim dtDate As DateTime = DateTime.Now
    Dim myFormat As String = "dddd dd MMMM yyyy"

    Thread.CurrentThread.CurrentCulture = New CultureInfo("af-ZA")
    txtDatum.Text = dtDate.ToString(myFormat, DateTimeFormatInfo.CurrentInfo)

    Dim ihour As Integer = CInt(Format(Now, "HH"))

    If ihour < 12 Then
      txtGroet.Text = "Goeie more, Jesus Leef!"
    ElseIf ihour < 17 Then
      txtGroet.Text = "Goeie middag, Leef jy vir Jesus!"
    Else
      txtGroet.Text = "Good aand, Jesus kom weer!"
    End If

    myFormat = "HH : mm : ss"
    txtTijd.Text = dtDate.ToString(myFormat, DateTimeFormatInfo.CurrentInfo)

End Sub

A couple of remarks:

1) You can use the same dtDate object to get date and time. This saves memory. If you state Dim dtDate As DateTime = DateTime.Now it records both the date and the time at that moment.
2) You don't have to use an array to define a string. This takes up a lot of memory and resources.
3) When you define iHour, you don't assign a value. It's value will always be 0 this way.
4) When you use Format to format dates, keep in mind that the letters are case sensitive! The reason the minute didn't advance was that it was the month (oktober = 10) you were showing. MM is the month, mm is minutes.

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
Ruffnekk

Thanks for the help, I am new to vb.net and I am trying to make make a program for our sunday school.

Greetings
Hendrik

 
I thought so :) I am Dutch and I can read your South-African spelling!

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
Toch genen hollander zeker?

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Jawel zulle!

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top