Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 4th, 2007, 05:49 PM
Friend of Wrox
 
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
Default setting system time

hi expert

i write sample application for setting system time and system date programatically

my code contains :

step 1) I import the kernel.dll for GetSystemTime && SetSystemTime

  
Quote:
quote:[DllImport("kernel32.dll")]
Quote:
static extern bool SetSystemTime(ref SYSTEMTIME time);
        [DllImport("kernel32.dll")]
static extern void GetSystemTime(out SYSTEMTIME lpSystemTime);
i write a structure such as follow

step 2 ) i write following structre

 
Quote:
quote:public struct SYSTEMTIME
Quote:
        {
            public short year;
            public short month;
            public short dayOfWeek;
            public short day;
            public short hour;
            public short minute;
            public short second;
            public short milliseconds;
        }



step 3) and finally i write in button1_click

 
Quote:
quote: try
Quote:
            {


                SYSTEMTIME time= new SYSTEMTIME();

                GetSystemTime(out time);
                time.hour = 12;
                time.year = 2001;
                SetSystemTime(ref time);
                MessageBox.Show("system time and date hase been changed successfully");
            }
            catch (Exception ex)
            {


                MessageBox.Show(ex.Message);
            }

and now my questions

1) as you see i set the hour to 12 but after clicking the button the system time seted to 4 PM , why?

2 )how can i set the year to 1386 ? in fact in above code where i set the year less than 2000 my code become ignore , why?

regards
 
Old May 4th, 2007, 08:05 PM
Authorized User
 
Join Date: Feb 2007
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Could it be that your time zone is what offsets the time? Try setting your zone to GMT and see if you get the same result.

There are 10 types of people - Those who understand binary, and those who don't.
http://bschleusner.googlepages.com/home





Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting Up A Development System For This Course ebstr BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 October 13th, 2008 09:27 AM
Insert System date and System Time -Form _TextBox cnkumar74 VB How-To 14 February 14th, 2007 10:52 AM
Setting Default Value at run time skinny Access 1 October 3rd, 2005 06:51 AM
Setting Design time property in webcustom control c_cicilia ASP.NET 1.x and 2.0 Application Design 1 September 23rd, 2004 10:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.