1、修改本机Windows的系统时间,Java代码实现:

  1. import java.io.IOException;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4.  
  5. public class ChangeWindowsDate {
  6.  
  7. /**
  8. * @param args
  9. * @throws IOException
  10. */
  11. public static void main(String[] args) {
  12. try {
  13. Runtime.getRuntime().exec("cmd /c date 2013-11-08") ;
  14. Runtime.getRuntime().exec("cmd /c time 18:10:00") ;
  15. } catch (IOException e) {
  16. e.printStackTrace() ;
  17. }
  18. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;
  19. Date date = new Date() ;
  20. System.out.println(sdf.format(date));
  21.  
  22. }
  23.  
  24. }

2、修改远程Linux Server的系统时间,Java代码实现:

  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.io.InputStreamReader;
  5. import ch.ethz.ssh2.Connection;
  6. import ch.ethz.ssh2.Session;
  7. import ch.ethz.ssh2.StreamGobbler;
  8.  
  9. public class ChangeLinuxDate {
  10.  
  11. /**
  12. * @param args
  13. */
  14. public static void main(String[] args) {
  15. String host_ip1 = "192.168.1.118" ;
  16. int port = 22 ;
  17. String username = "root" ;
  18. String password = "123456" ;
  19.  
  20. String cmd = "date -s '2013-08-04 23:00:00'" ;
  21.  
  22. Connection conn1 = new Connection(host_ip1, port) ;
  23. Session session1 = null ;
  24.  
  25. try {
  26. conn1.connect() ;
  27. boolean isconn = conn1.authenticateWithPassword(username, password) ;
  28. if(!isconn){
  29. System.out.println("用户名称或者是密码不正确");
  30. }else{
  31. System.out.println(host_ip1 + ":" + "已经连接OK");
  32. session1 = conn1.openSession() ;
  33. session1.execCommand(cmd) ;
  34.  
  35. InputStream is = new StreamGobbler(session1.getStdout());
  36. BufferedReader brs = new BufferedReader(new InputStreamReader(is));
  37. while(true){
  38. String line = brs.readLine();
  39. if(line==null){
  40. break;
  41. }
  42. System.out.println(line);
  43. }
  44. is.close() ;
  45. brs.close() ;
  46. session1.close() ;
  47. conn1.close() ;
  48. }
  49.  
  50. } catch (IOException e) {
  51. e.printStackTrace() ;
  52. }
  53.  
  54. }
  55.  
  56. }

修改Windows和linux系统时间的更多相关文章

  1. 修改linux系统时间的方法(date命令)

    修改linux系统时间的方法(date命令) 来源:互联网 作者:佚名 时间:11-18 23:22:27 [大 中 小] date命令不仅可以显示系统当前时间,还可以用它来修改系统时间,下面简单的介 ...

  2. Linux的硬件时间、校正Linux系统时间及系统时间调用流程

    第一部分: 一)概述: 事实上在Linux中有两个时钟系统,分别是系统时间和硬件时间 UTC是协调世界时(Universal Time Coordinated)英文缩写,它比北京时间早8个小时.   ...

  3. Linux_自动调整linux系统时间和时区与Internet时间同步

    调整linux系统时间和时区与Internet时间同步 一.修改时区:# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime修改为中国的东八区# v ...

  4. Redis进阶实践之六Redis Desktop Manager连接Windows和Linux系统上的Redis服务

    一.引言 今天本来没有打算写这篇文章,当初我感觉使用这个工具应该很简单,下载的过程也不复杂,也没有打算记录下来.但是在使用的过程中还是出现了一些问题,为了给第一次使用Redis Desktop Man ...

  5. Linux系统时间的设置

    1. Linux系统时间的设置 在Linux中设置系统时间,可以用date命令: //查看时间[root@node1 ~]# dateTue Feb 25 20:15:18 CST 2014//修改时 ...

  6. Linux系统时间同步方法小结

    在Windwos中,系统时间的设置很简单,界面操作,通俗易懂,而且设置后,重启,关机都没关系.系统时间会自动保存在BIOS时钟里面,启动计算机的时候,系统会自动在BIOS里面取硬件时间,以保证时间的不 ...

  7. 自动调整linux系统时间和时区与Internet时间同步

    调整linux系统时间和时区与Internet时间同步 一.修改时区:# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime修改为中国的东八区# v ...

  8. Redis进阶实践之六Redis Desktop Manager连接Windows和Linux系统上的Redis服务(转载6)

    Redis进阶实践之六Redis Desktop Manager连接Windows和Linux系统上的Redis服务 一.引言 今天本来没有打算写这篇文章,但是,今天测试Redis的时候发现了两个问题 ...

  9. Linux学习之十-Linux系统时间

    Linux系统时间 1.date命令用于查看以及修改Linux系统的时间,关于date命令的详细帮助文档如下 [root@localhost ~]# date --help Usage: date [ ...

随机推荐

  1. centos7 安装后需要做的事情

    安装centos 7 系统之后要做的几件事 #修改主机名 hostnamectl --static set-hostname xd-1 vim /etc/hosts127.0.0.1 xd-1x.x. ...

  2. vue-router路由的使用

    1.路由作用 用vue.js + vue-router创建单页面应用.页面不需要刷新就可以页面跳转,提供用户更好体验. 2.路由配置 new Router({ routes: [{ path: '/' ...

  3. asp.net 中用easyui中的treegird的简单使用

    几乎每个‘数人头’项目中都会用到的功能,这里先记下来,以后直接到这里复制代码就行了,ASP.NET MVC中的使用 数据库用户表中的除了有个parentid父级ID外,我还多加了以个字段,parent ...

  4. Atitit 个人信息数据文档知识分类

    Atitit 个人信息数据文档知识分类 1.1. 知识分类法,参照图书分类法 1 2. Attilax知识分类 2 2.1. 公共文档(一般技术资料,通过标题可以网上搜索到的) 2 2.2. sum ...

  5. PostgreSQL判断是否为空coalesce

    coalesce(expr1,expr2,expr3...) 直到找到一个非null值返回,右边的表达式则不参与运算:若所有为null,返回null. eg:判断json是否包含某属性,若无,则取默认 ...

  6. create-react-app的使用及原理分析

    create-react-app 是一个全局的命令行工具用来创建一个新的项目 react-scripts 是一个生成的项目所需要的开发依赖 一般我们开始创建react web应用程序的时候,要自己通过 ...

  7. GoLang-字符串

    初始化 var str string //声明一个字符串 str = "laoYu" //赋值 ch :=str[0] //获取第一个字符 len :=len(str) //字符串 ...

  8. angular-resource版本差异问题

    在 AngularJS v1.3.0-beta.14 这个版本里,使用query方法,如果传递进来的数据不是数组,会报错. 在 AngularJS v1.2.18 这个版本里,使用query方法,如果 ...

  9. 【内核】内核链表使用说明,list.h注释

    list_entry定义 /** * list_entry - get the struct for this entry * @ptr: the &struct list_head poin ...

  10. git file mode change

    近期在做ffmpeg版本合并时发现,TortoiseGit的Check for Modifications的修改对话框中有未修改的问题,直接导出diff,会有类似下面的输出: compat/plan9 ...