473,233 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,233 software developers and data experts.

changing the system date from javacode

Hi ,

I want to change the system date using java/jsp . i am using linux system .

public class LinuxJava {
public static void main(String[] args) {
try {
String command = "date 07212008";
final Process process = Runtime.getRuntime().exec(command);

// int returnCode = process.waitFor();
// process.toString()
System.out.println("Return code = " + process.toString());
} catch (Exception e) {
e.printStackTrace();
}
}

}

i tried this code it didn't change the code . can any one tell how to change the system date with java application ?
Jul 21 '08 #1
11 11207
JosAH
11,448 Expert 8TB
What *did* it do? What was the completion code of the process? Any exceptions
thrown? Is the effective user allowed to change the system date?

kind regards,

Jos
Jul 21 '08 #2
no exception thrown it is executing the code but it is not chaning the date .

for chaning the date we need to have root permision . may be beacuse of that it is not executing .

i tried with this command also

String command = "date -s 'Sat May 24 14:43:00 PDT 2005' "; in place of
String command = "date 07212008'
Jul 21 '08 #3
JosAH
11,448 Expert 8TB
no exception thrown it is executing the code but it is not chaning the date .

for chaning the date we need to have root permision . may be beacuse of that it is not executing .
Sure, you have to be root to change the system date so you have to run your
little program with an effective uid set to root.

kind regards,

Jos
Jul 21 '08 #4
samido
52
I am not sure what this suppose to do but the type of exception is as follow, somebody please help out so that we can all learn this thign

java.io.IOException: Cannot run program "date": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at Test.main(Test.java:16)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more

kind regarde:

Sam Rabophala
Jul 21 '08 #5
i have changed the class file user as root but still it is not working .
anything else i need to do ?



Sure, you have to be root to change the system date so you have to run your
little program with an effective uid set to root.

kind regards,

Jos
Jul 21 '08 #6
i tried by writing the one shell script with root permision .

# Author: Rashmi
# date : 01-07-2005

date -s 'May 12 2008'


and calling that one with java code

public class LinuxJava {
public static void main(String[] args) {
try {
String command = "/home/rashmi/test.sh ";
final Process process = Runtime.getRuntime().exec(command);

// int returnCode = process.waitFor();
// process.toString()
System.out.println("Return code = " + process.toString());

} catch (Exception e) {
e.printStackTrace();
}
}

}


it is also executing .. but not chaning the date :(
Jul 21 '08 #7
JosAH
11,448 Expert 8TB
i tried by writing the one shell script with root permision .

[ ... ]

it is also executing .. but not chaning the date :(
If you run that script manually, does it change the date?

kind regards,

Jos
Jul 21 '08 #8
now i am able to change the date , i changed the tomcat user to root . and script user to root . now it started working .
thanks
Jul 24 '08 #9
r035198x
13,262 8TB
now i am able to change the date , i changed the tomcat user to root . and script user to root . now it started working .
thanks
Oh so Tomcat was involved in all this? I didn't pick that up from your ealier posts in this thread.
Jul 24 '08 #10
i wanted do this either by the stand alone java program or from the application .
after chaning the tomcat to root user , i called the java program program from jsp . then it started working .
Jul 24 '08 #11
hi ksrashmi,

can you please paste the content that was there in
/home/rashmi/test.sh.

Thanks,
Pradeep.
Aug 4 '16 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John Smith | last post by:
Hey folks, I've got a combobox (DropDown List) in a windows form application which is bound to a DataSet. It's value is set to a numeric ID. It's visible text is set to a date. I need to make...
1
by: Robert Bravery | last post by:
HI all, I am new to .net and c#. How can I change the system date based on user input on an textbox on a form Thanks Robert
5
by: Mark Fox | last post by:
Hello, When you add a new web form in VS.NET it automatically adds the following namespaces at the top: using System; using System.Collections; using System.ComponentModel; using...
0
by: gh0st54 | last post by:
Hi i'm looking for how to change the date of out going messages i tried this but it doesn't seems to work static public bool SendEmail(string To, string From, string Subject, string Body,...
2
by: barry | last post by:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim curtime As Date Do Until Date.Now >= some future date time curtime = Date.Now...
7
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
20
by: andreas | last post by:
When I copy a vb.net project using date formats from one PC with a windows date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I get errors. How can I change for a while in the...
0
by: jeanuta | last post by:
boolean retval = false; StringBuffer sql = new StringBuffer(); ResultSet rst = null; conn.setAutoCommit(false); sql.append("select assign_customers() "); Statement st =...
18
JamesDC
by: JamesDC | last post by:
Hi, So I'm working with an Access 2002 database for waste managemnt. The person in my role before my put together the program before he left and now I'm in charge of it. After updating a few...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.