修改Windows和linux系统时间
1、修改本机Windows的系统时间,Java代码实现:
- import java.io.IOException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- public class ChangeWindowsDate {
- /**
- * @param args
- * @throws IOException
- */
- public static void main(String[] args) {
- try {
- Runtime.getRuntime().exec("cmd /c date 2013-11-08") ;
- Runtime.getRuntime().exec("cmd /c time 18:10:00") ;
- } catch (IOException e) {
- e.printStackTrace() ;
- }
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;
- Date date = new Date() ;
- System.out.println(sdf.format(date));
- }
- }
2、修改远程Linux Server的系统时间,Java代码实现:
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import ch.ethz.ssh2.Connection;
- import ch.ethz.ssh2.Session;
- import ch.ethz.ssh2.StreamGobbler;
- public class ChangeLinuxDate {
- /**
- * @param args
- */
- public static void main(String[] args) {
- String host_ip1 = "192.168.1.118" ;
- int port = 22 ;
- String username = "root" ;
- String password = "123456" ;
- String cmd = "date -s '2013-08-04 23:00:00'" ;
- Connection conn1 = new Connection(host_ip1, port) ;
- Session session1 = null ;
- try {
- conn1.connect() ;
- boolean isconn = conn1.authenticateWithPassword(username, password) ;
- if(!isconn){
- System.out.println("用户名称或者是密码不正确");
- }else{
- System.out.println(host_ip1 + ":" + "已经连接OK");
- session1 = conn1.openSession() ;
- session1.execCommand(cmd) ;
- InputStream is = new StreamGobbler(session1.getStdout());
- BufferedReader brs = new BufferedReader(new InputStreamReader(is));
- while(true){
- String line = brs.readLine();
- if(line==null){
- break;
- }
- System.out.println(line);
- }
- is.close() ;
- brs.close() ;
- session1.close() ;
- conn1.close() ;
- }
- } catch (IOException e) {
- e.printStackTrace() ;
- }
- }
- }
修改Windows和linux系统时间的更多相关文章
- 修改linux系统时间的方法(date命令)
修改linux系统时间的方法(date命令) 来源:互联网 作者:佚名 时间:11-18 23:22:27 [大 中 小] date命令不仅可以显示系统当前时间,还可以用它来修改系统时间,下面简单的介 ...
- Linux的硬件时间、校正Linux系统时间及系统时间调用流程
第一部分: 一)概述: 事实上在Linux中有两个时钟系统,分别是系统时间和硬件时间 UTC是协调世界时(Universal Time Coordinated)英文缩写,它比北京时间早8个小时. ...
- Linux_自动调整linux系统时间和时区与Internet时间同步
调整linux系统时间和时区与Internet时间同步 一.修改时区:# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime修改为中国的东八区# v ...
- Redis进阶实践之六Redis Desktop Manager连接Windows和Linux系统上的Redis服务
一.引言 今天本来没有打算写这篇文章,当初我感觉使用这个工具应该很简单,下载的过程也不复杂,也没有打算记录下来.但是在使用的过程中还是出现了一些问题,为了给第一次使用Redis Desktop Man ...
- Linux系统时间的设置
1. Linux系统时间的设置 在Linux中设置系统时间,可以用date命令: //查看时间[root@node1 ~]# dateTue Feb 25 20:15:18 CST 2014//修改时 ...
- Linux系统时间同步方法小结
在Windwos中,系统时间的设置很简单,界面操作,通俗易懂,而且设置后,重启,关机都没关系.系统时间会自动保存在BIOS时钟里面,启动计算机的时候,系统会自动在BIOS里面取硬件时间,以保证时间的不 ...
- 自动调整linux系统时间和时区与Internet时间同步
调整linux系统时间和时区与Internet时间同步 一.修改时区:# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime修改为中国的东八区# v ...
- Redis进阶实践之六Redis Desktop Manager连接Windows和Linux系统上的Redis服务(转载6)
Redis进阶实践之六Redis Desktop Manager连接Windows和Linux系统上的Redis服务 一.引言 今天本来没有打算写这篇文章,但是,今天测试Redis的时候发现了两个问题 ...
- Linux学习之十-Linux系统时间
Linux系统时间 1.date命令用于查看以及修改Linux系统的时间,关于date命令的详细帮助文档如下 [root@localhost ~]# date --help Usage: date [ ...
随机推荐
- centos7 安装后需要做的事情
安装centos 7 系统之后要做的几件事 #修改主机名 hostnamectl --static set-hostname xd-1 vim /etc/hosts127.0.0.1 xd-1x.x. ...
- vue-router路由的使用
1.路由作用 用vue.js + vue-router创建单页面应用.页面不需要刷新就可以页面跳转,提供用户更好体验. 2.路由配置 new Router({ routes: [{ path: '/' ...
- asp.net 中用easyui中的treegird的简单使用
几乎每个‘数人头’项目中都会用到的功能,这里先记下来,以后直接到这里复制代码就行了,ASP.NET MVC中的使用 数据库用户表中的除了有个parentid父级ID外,我还多加了以个字段,parent ...
- Atitit 个人信息数据文档知识分类
Atitit 个人信息数据文档知识分类 1.1. 知识分类法,参照图书分类法 1 2. Attilax知识分类 2 2.1. 公共文档(一般技术资料,通过标题可以网上搜索到的) 2 2.2. sum ...
- PostgreSQL判断是否为空coalesce
coalesce(expr1,expr2,expr3...) 直到找到一个非null值返回,右边的表达式则不参与运算:若所有为null,返回null. eg:判断json是否包含某属性,若无,则取默认 ...
- create-react-app的使用及原理分析
create-react-app 是一个全局的命令行工具用来创建一个新的项目 react-scripts 是一个生成的项目所需要的开发依赖 一般我们开始创建react web应用程序的时候,要自己通过 ...
- GoLang-字符串
初始化 var str string //声明一个字符串 str = "laoYu" //赋值 ch :=str[0] //获取第一个字符 len :=len(str) //字符串 ...
- angular-resource版本差异问题
在 AngularJS v1.3.0-beta.14 这个版本里,使用query方法,如果传递进来的数据不是数组,会报错. 在 AngularJS v1.2.18 这个版本里,使用query方法,如果 ...
- 【内核】内核链表使用说明,list.h注释
list_entry定义 /** * list_entry - get the struct for this entry * @ptr: the &struct list_head poin ...
- git file mode change
近期在做ffmpeg版本合并时发现,TortoiseGit的Check for Modifications的修改对话框中有未修改的问题,直接导出diff,会有类似下面的输出: compat/plan9 ...