Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 16:03:10
Original
1000 people have browsed it

使用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();
    });
  }
});
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template