Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,100 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,865 people online right now. Registration is fast and FREE... Join Now!




Modify System date and time

 
Reply to this topicStart new topic

Modify System date and time, code snippet

smyle22
6 Jun, 2008 - 03:00 AM
Post #1

New D.I.C Head
*

Joined: 6 Jun, 2008
Posts: 5

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

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

User is offlineProfile CardPM
+Quote Post

RodgerB
RE: Modify System Date And Time
6 Jun, 2008 - 05:02 AM
Post #2

D.I.C Lover
Group Icon

Joined: 21 Sep, 2007
Posts: 2,166



Thanked: 17 times
Dream Kudos: 2200
Expert In: Dot Net Technologies

My Contributions
Do you have a question here, or do you have a snippet to submit? You can submit a VB.NET snippet by following this link: http://www.dreamincode.net/code/input.php?cid=18
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 12:30AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month