Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


How to modify System date and time in vb .net code?


How to modify System date and time in vb .net code?

Author
Message
smyle22
smyle22
Forum God
Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)

Group: Forum Members
Posts: 9, Visits: 13
Someone.. pls help me how to modify system date thru code in vb .net

thanks..

smyle
AllenSmith
AllenSmith
Forum God
Forum God (3.1K reputation)Forum God (3.1K reputation)Forum God (3.1K reputation)Forum God (3.1K reputation)Forum God (3.1K reputation)Forum God (3.1K reputation)Forum God (3.1K reputation)Forum God (3.1K reputation)Forum God (3.1K reputation)

Group: Forum Members
Posts: 21, Visits: 335
Hello Smyle,

You may try the given code snippet. Let's say we are changing the time on a button click:

BEGIN CODE

Imports System.Runtime.InteropServices

Public Class Form1

'System time structure used to pass to P/Invoke...

<StructLayoutAttribute(LayoutKind.Sequential)> _

Private Structure SYSTEMTIME

Public year As Short

Public month As Short

Public dayOfWeek As Short

Public day As Short

Public hour As Short

Public minute As Short

Public second As Short

Public milliseconds As Short

End Structure

'P/Invoke dec for setting the system time...

<DllImport("Kernel32.dll")> _

Private Shared Function SetLocalTime(ByRef time As SYSTEMTIME) As Boolean

End Function

Public Function SetDeviceTime(ByVal p_NewDate As Date)

'Populate structure...

'Substitute <YOUR DATE OBJECT> with your date object returned via GPRS...

Dim st As SYSTEMTIME

st.year = p_NewDate.Year

st.month = p_NewDate.Month

st.dayOfWeek = p_NewDate.DayOfWeek

st.day = p_NewDate.Day

st.hour = p_NewDate.Hour

st.minute = p_NewDate.Minute

st.second = p_NewDate.Second

st.milliseconds = p_NewDate.Millisecond

'Set the new time...

SetLocalTime(st)

End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

SetDeviceTime("01/01/2009")

End Sub

End Class


END CODE

I hope this will help.

Regards,

Allen Smith

Allen Smith



Software Engineer

ComponentOne LLC

www.componentone.com

smyle22
smyle22
Forum God
Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)

Group: Forum Members
Posts: 9, Visits: 13
Thanks alot sir.. it really works..

smyle
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search