How to set System Date & time

Thread Solved

Join Date: Mar 2008
Posts: 41
Reputation: ramjeev is an unknown quantity at this point 
Solved Threads: 0
ramjeev ramjeev is offline Offline
Light Poster

How to set System Date & time

 
0
  #1
Mar 14th, 2008
Hi buddies,
I m facing some difficulties while setting system date and time?..Can anyone help to set System date & time?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 126
Reputation: new_2_java is an unknown quantity at this point 
Solved Threads: 6
new_2_java new_2_java is offline Offline
Junior Poster

Re: How to set System Date & time

 
0
  #2
Mar 14th, 2008
- Open a command prompt
- Type in: date
- it prompts you for new date/time
- enter new values.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 41
Reputation: ramjeev is an unknown quantity at this point 
Solved Threads: 0
ramjeev ramjeev is offline Offline
Light Poster

Re: How to set System Date & time

 
0
  #3
Mar 15th, 2008
Originally Posted by new_2_java View Post
- Open a command prompt
- Type in: date
- it prompts you for new date/time
- enter new values.

Thanks for reply.I want to set date & time programatically thru Java.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 791
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 109
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster

Re: How to set System Date & time

 
0
  #4
Mar 15th, 2008
You can GET the date and time by using
  1. System.currentTimeMillis();
This returns a long type that represents the number of milliseconds since Jan 1, 1970. You can format that long by using the java.util.Calendar and java.text.DateFormat classes.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 41
Reputation: ramjeev is an unknown quantity at this point 
Solved Threads: 0
ramjeev ramjeev is offline Offline
Light Poster

Re: How to set System Date & time

 
0
  #5
Mar 15th, 2008
Originally Posted by darkagn View Post
You can GET the date and time by using
  1. System.currentTimeMillis();
This returns a long type that represents the number of milliseconds since Jan 1, 1970. You can format that long by using the java.util.Calendar and java.text.DateFormat classes.

I m using Calendar class only as follows,

Calendar date = Calendar.getInstance();
date.set(i_year,i_mon,i_dt,i_hr,i_min,i_sec);
System.out.println("...."+date.get(Calendar.HOUR_OF_DAY)+"..."+date.get(Calendar.MINUTE)+"..."+date.get(Calendar.SECOND));


After setting the date,time ,I can fetch the updated date for this same instance thru programatically but still i can see the old time in system calendar.
For anyother instance as below ,i can get only the old date and not the updated one.

Calendar dateNew = Calendar.getInstance();


Please help.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,438
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: How to set System Date & time

 
0
  #6
Mar 15th, 2008
The only way that you would be able to set the system time is through JNI calls to the OS.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 41
Reputation: ramjeev is an unknown quantity at this point 
Solved Threads: 0
ramjeev ramjeev is offline Offline
Light Poster

Re: How to set System Date & time

 
0
  #7
Mar 17th, 2008
Originally Posted by Ezzaral View Post
The only way that you would be able to set the system time is through JNI calls to the OS.
Thanks.
I dont know how to use JNI , if u hav samples ,pls guide me with that.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 41
Reputation: ramjeev is an unknown quantity at this point 
Solved Threads: 0
ramjeev ramjeev is offline Offline
Light Poster

Re: How to set System Date & time

 
0
  #8
Mar 17th, 2008
Originally Posted by ramjeev View Post
Thanks.
I dont know how to use JNI , if u hav samples ,pls guide me with that.

I got a way to fix this,

String timestr="15:00";
String datestr="03-15-2008";
Runtime rt = Runtime.getRuntime();
Process proc;
proc = rt.exec("cmd /C date " + datestr);
proc = rt.exec("cmd /C time " + timestr);

However,this can only work on windows.

Thanks a lot for all ur support.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC