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="imgArea">
  <img id="targetImg" src="https://picsum.photos/id/613/2000/2000.jpg?hmac=fXdDqYnKfr4TCvhnggZhXF20-5O1MOhQPI84s0Vo_tY" />
  <p id="imgInfo"></p>
</div>
              
            
!

CSS

              
                img {
  max-width: 300px;
}
              
            
!

JS

              
                (async () => {
  // 要素を取得
  const targetImg = document.querySelector("#targetImg");
  const imgInfo =  document.querySelector("#imgInfo");
  
  // 画像データを非同期で取得
  const fetchImg = await fetchImage(targetImg.src);
  // 更新日時を取得
  const modified = getModified(fetchImg);
  // 更新日時を表示
  imgInfo.textContent = "更新日時:" + formatDate(modified)
})();

// fetch(非同期)
async function fetchImage(target) {
  const response = await fetch(target);
  if (response.ok) {
    return response;
  } else {
      throw new Error('The data could not be read');
   }
}

// 更新日取得
function getModified(target) {
  const headers = target.headers;
  let lastModified = "";
  // 更新日時を取得(GMT)
  for (var pair of headers.entries()) {
    if (pair[0] === "last-modified") {
      lastModified = pair[1];
     
    }
  }
  return lastModified;
}

// GMTを年月日分に変換
function formatDate(targetDate) {
  const modified = new Date(targetDate);
  const year = modified.getFullYear();
  const month = modified.getMonth() + 1;
  const date = modified.getDate();
  const hours = modified.getHours();
  const minutes = modified.getMinutes();
  return +year + "年" + month + "月" + date + "日" + hours + "時" + minutes + "分";
};





              
            
!
999px

Console