2016年10月5日水曜日

開発環境

Exercises for Programmers: 57 Challenges to Develop Your Coding Skills (Brian P. Hogan 著、Pragmatic Bookshelf)のChapter 9(Working with External Services)、52(Creating Your Own Time Service)を取り組んでみる。

49(Creating Your Own Time Service)

コード(Emacs)

HTML5

<div id="output0"></div>
<script src="sample52.js"></script>

JavaScript

{
    'use strict';
    let div_output = document.querySelector('#output0');

    let getCurrentTime = () => {
        let o = {currentTime: new Date().toISOString()};

        return JSON.stringify(o);
    };
    let output = () => {
        let json = getCurrentTime(),
            o = JSON.parse(json),
            s = o.currentTime,
            millseconds  = Date.parse(s),
            d = new Date(millseconds);

        div_output.innerText = `The current time is ${d.toUTCString()}.`;
    };
    output();
    setInterval(output, 1);
}

0 コメント:

コメントを投稿

Comments on Google+: