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 class="wrapper">
  <input type="date" class="input-date">
  <button class="btn">表示する</button>
  <p class="display"></p>
</div>
              
            
!

CSS

              
                .wrapper {
  text-align: center;
  margin-top: 60px;
}

.display {
  margin-top: 30px;
}
              
            
!

JS

              
                //inputフォームを取得
const inputDate = document.querySelector('.input-date');
//ボタンを取得
const btn = document.querySelector('.btn');
//日付を表示するためのpタグを取得
const display = document.querySelector('.display');

//ボタンをクリックすると処理を実行
btn.addEventListener('click', () => {
  //日付を選択していないときは処理が終了
  if(!inputDate.value) {
    return;
  }
  
  
  //日付を取得
  const fullDate = new Date(inputDate.value);
  //年を取得
  const getYear = fullDate.getFullYear();
 //月を取得
  const getMonth = fullDate.getMonth() + 1;
 //日を取得
  const getDate = fullDate.getDate();
  
  // 日付を2024/1/1の形式にする
  const formattedDate = `${getYear}/${getMonth}/${getDate}`;
  
  //pタグに日付を代入
  display.innerText = '入力した日付: ' + formattedDate;
});
              
            
!
999px

Console