Home  >  Article  >  Web Front-end  >  Use the jsdom library of iojs to synchronize system time_node.js

Use the jsdom library of iojs to synchronize system time_node.js

WBOY
WBOYOriginal
2016-05-16 16:03:10994browse

使用iojs的jsdom库与 http://open.baidu.com/special/time/ 同步系统时间。

var jsdom = require("jsdom");
var exec = require('child_process').exec;
 
jsdom.env({
  url: "http://open.baidu.com/special/time/",
  scripts: ["D:\\jquery-1.9.1.min.js"],
  features: {
    ProcessExternalResources: ["script"]
  },
  done: function (errors, window) {
    var $ = window.$;
    var curtime = $('#time').text();
    console.log('get time: ' + curtime);
 
    // 更新系统时间
    exec('time ' + curtime, function(err, stdout, stderr) {
      console.log('change time ' + curtime + ': ' + (err ? err : 'success'));
      process.exit();
    });
  }
});

以上所述就是本文的全部内容了,希望大家能够喜欢。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn