从javacode更改系统日期 [英] changing the system date from javacode

查看:71
本文介绍了从javacode更改系统日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想用java / jsp更改系统日期。我正在使用linux系统。


公共类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(例外e){

e.printStackTrace();

}

}


}


i尝试了这段代码,它并没有改变代码。任何人都可以告诉你如何用java应用程序更改系统日期?

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 ?

推荐答案

它做了什么*做了什么?该流程的完成代码是什么?任何例外

抛出?是否允许有效用户更改系统日期?


亲切的问候,


Jos
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


没有异常抛出它正在执行代码,但它没有处理日期。


用于查询我们需要根除的日期。可能是因为它没有执行。


i也试过这个命令


String command =" date -s''Th 5月24日14:43:00 PDT 2005' '';代替

String command =" date 07212008''
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''



没有异常抛出它正在执行代码,但它没有chaning日期。


用于查询我们需要根除的日期。可能是因为它没有执行。
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 .



当然,你必须是root才能改变系统日期,所以你必须运行你的

小程序,并设置有效的uid root。


亲切的问候,


Jos

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


这篇关于从javacode更改系统日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆