Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="clock"></div>
              
            
!

CSS

              
                
              
            
!

JS

              
                /**
 * 指定した桁数に0埋めする関数
 * @param {int} num 対象の数値
 * @param {int} zeroLength 埋めたい0の数
 * @return {String} 0埋めされた文字列
 */
const zeroPadding = (num, zeroLength) => {
  // "0"を入れるための変数
  let zero = "";

  // zeroLength個の"0"をつける
  for (let i = 0; i < zeroLength; i++) {
    zero += "0";
  }

  // numの前に指定した数の"0"をつけ、末尾の文字数を削る
  return (zero + num).slice(-zeroLength);
};

// 時計表示用のHTMLの要素を取得
const clockElement = document.getElementById("clock");

/**
 * 現在時刻を取得し、DOMを書き換える関数
 */
const clockSetting = () => {
  // クラスのインスタンス化
  const currentDate = new Date();
  // 年
  const year = currentDate.getFullYear();
  // 月
  const month = currentDate.getMonth() + 1;
  // 日
  const day = currentDate.getDate();
  // 曜日のリスト
  const dayOfWeek = ["日", "月", "火", "水", "木", "金", "土"];
  // 曜日の番号を取得
  const weekNumber = currentDate.getDay();
  // 時間
  const hour = currentDate.getHours();
  // 分
  const min = currentDate.getMinutes();
  // 秒
  const sec = currentDate.getSeconds();

  // 現在時刻
  const myClock =
    year +
    "/" +
    zeroPadding(month, 2) +
    "/" +
    zeroPadding(day, 2) +
    " " +
    dayOfWeek[weekNumber] +
    "曜日 " +
    zeroPadding(hour, 2) +
    ":" +
    zeroPadding(min, 2) +
    ":" +
    zeroPadding(sec, 2);

  // DOMの書き換え
  clockElement.innerHTML = myClock;
};

// 1000ミリ秒間隔でclockSetting関数を実行する
setInterval(clockSetting, 1000);

              
            
!
999px

Console