zoukankan      html  css  js  c++  java
  • JavaScript Basic

    Exercise-1

    Write a JavaScript program to display the current day and time in the following format.
    Today is : Tuesday.
    Current time is : 2PM : 21 : 38

    const today = new Date();
    const day = today.getDay();
    const daylist = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
    console.log(`Today is ${daylist[day]}`);
    
    let hour = today.getHours();
    const minute = today.getMinutes();
    const second = today.getSeconds();
    let prepand = (hour >= 12) ? "PM" : "AM";
    hour = (hour >= 12) ? hour - 12 : hour;
    
    if (hour === 0 && prepand === 'PM') {
    	if (minute === 0 && second === 0) {
    		hour = 12;
    		prepand = 'Noon';
    	} else {
    		hour = 12;
    		prepand = 'PM';
    	}
    }
    
    if (hour === 0 && prepand === 'AM') {
    	if (minute === 0 && second === 0) {
    		hour = 12;
    		prepand = `Midnight`;
    	} else {
    		hour = 12;
    		prepand = 'AM';
    	}
    }
    console.log(`Current Time ${hour}${prepand} : ${minute} : ${second}`);
  • 相关阅读:
    UML建模之用例图关系
    python模块介绍
    Delphi操作XML(七)
    Delphi操作XML(一)
    Delphi操作XML(五)
    Delphi操作XML(六)
    Delphi操作XML(二)
    Delphi操作XML(四)
    Delphi操作XML(三)
    决心好好写cnblogs
  • 原文地址:https://www.cnblogs.com/PrimerPlus/p/12767206.html
Copyright © 2011-2022 走看看