JavaScript´Â ³¯Â¥¸¦ ó¸®ÇÒ ¶§
1970³â 1¿ù 1ÀÏ 0½ÃºÎÅÍ 0À¸·Î ½ÃÀÛÇؼ
¹Ð¸®ÃÊ´ÜÀ§·Î ½Ã°£À» ±¸ºÐÇÏ°í ÀÖ½À´Ï´Ù.
±×·¡¼ ³»ºÎÀûÀ¸·Î 1433961056771 ½ÄÀÇ ¼ýÀÚÇü µ¥ÀÌÅÍ¿¡
³¯Â¥ Çü½ÄÀ» ¸ðµÎ ´ã°í ÀÖ´Â °ÍÀÔ´Ï´Ù.
À̸¦ »ç¿ëÇÏ¿© getDate()¸¦ »ç¿ëÇÏ¿© ³¯Â¥¸¦
getMonth()¸¦ »ç¿ëÇÏ¿© ¿ù Á¤º¸ µîÀ» °¡Á®¿É´Ï´Ù.
±×¸®°í ³¯Â¥Çü½ÄÀÇ °³Ã¼¿¡¼
getDay()¸¦ »ç¿ëÇؼ ÇöÀç ¿äÀÏÀ»(ÀÏ¿äÀÏ:0~Åä¿äÀÏ:6) Çü½ÄÀ¸·Î °¡Á®¿À´Â °ÍÀÔ´Ï´Ù.
¾Æ·¡ »ùÇà ÄÚµå´Â Á¦ °ÀÇ ¼Ò½º Áß ÀϺÎÀÌ´Ï Âü°íÇØ º¸½Ã±â ¹Ù¶ø´Ï´Ù.
// ÇöÀç ½Ã°£
var d = new Date();
//document.getElementById("lblDate").innerHTML = d; // Thu Jun 11 2015 03:27:45 GMT+0900 (´ëÇѹα¹ Ç¥ÁؽÃ)
document.getElementById("lblDate").innerHTML = d.getTime(); // 1970³â 1¿ù 1ÀÏ 00½Ã 00ºÐ 00ÃʺÎÅÍ ½Ã°£À» °è»êÇؼ ¹Ð¸®ÃÊ´ÜÀ§·Î ±¸ºÐÇؼ Ç¥Çö
// ƯÁ¤ ½Ã°£: ¼ýÀÚÇü
var d2 = new Date(1433961056771);
document.getElementById("lblDate2").innerHTML = d2;
// ƯÁ¤ ½Ã°£: ¹®ÀÚ¿
var d3 = new Date("Thu Jun 11 2015 03:27:45 GMT+0900 (´ëÇѹα¹ Ç¥ÁؽÃ)");
console.log(d3);
console.log(d3.getTime());
// ƯÁ¤ ½Ã°£ ÁöÁ¤
var d4 = new Date(2015, 05, 11); // ¿ù: 0~11¿ù => 2015³â 6¿ù 11ÀÏ
console.log(d4);
console.log(d4.getTime());
// ¿ù¸¸ Ç¥Çö
console.log(((new Date().getMonth()) + 1) + "¿ù"); // 6¿ùÀε¥ 5·Î Ç¥½Ã, ±×·¡¼ Á¤È®ÇÑ Ç¥Çö½Ã +1À» ÇؾßÇÔ
// ¿äÀϸ¸ Ç¥Çö
console.log((new Date().getDay()) + "¿äÀÏ"); // ÀÏ¿äÀÏ(0)~Åä¿äÀÏ(6)
ÁÖ¼¼ÈÆ ´ÔÀÌ ¾²½Å ¿ø¹® ±ÛÀÔ´Ï´Ù.
°ÀǸ¦ º¸¸ç ÂüÁ¶ÇÏ°í Àִ åÀε¥... Àǹ®ÀÌ »ý°Ü¼ Áú¹®µå¸³´Ï´Ù.
¾Æ·¡ Äڵ忡¼...
weekFromToday = new Date(today.getTime() + 7 * 24 * 60 * 60 * 1000);
weekFromTodayÀÇ Date°´Ã¼´Â getTime()À̶ó´Â ¸Þ¼Òµå¸¦ »ç¿ëÇÏ¿© ¹Ð¸®¼¼ÄÁµå °ªÀ» °¡Áö°Ô µÇ´Âµ¥....
±× ¾Æ·¡ Äڵ带 º¸¸é...
day = dayNames[weekFromToday.getDay()]; À̶õ Äڵ尡 ³ª¿É´Ï´Ù.
weekFromToday °´Ã¼ °ªÀº ¹Ð¸®¼¼ÄÁµåÀε¥ ¿©±â¼ ¾î¶»°Ô getDay() Áï, ¿äÀÏ°ª(0~6)À» °¡Áö°í ¿Ã ¼ö ÀÖ´ÂÁö ÀÌÇØ°¡ °¡Áú ¾Ê½À´Ï´Ù.
´äº¯ ºÎŹµå¸®°Ú½À´Ï´Ù.
------------------------------------------------------------------------
/* The script is placed inside an immediately invoked function expression
which helps protect the scope of variables */
(function() {
// PART ONE: CREATE HOTEL OBJECT AND WRITE OUT THE OFFER DETAILS
// Create a hotel object using object literal syntax
var hotel = {
name: 'Park',
roomRate: 240, // Amount in dollars
discount: 15, // Percentage discount
offerPrice: function() {
var offerRate = this.roomRate * ((100 - this.discount) / 100);
return offerRate;
}
};
// Write out the hotel name, standard rate, and the special rate
var hotelName, roomRate, specialRate; // Declare variables
hotelName = document.getElementById('hotelName'); // Get elements
roomRate = document.getElementById('roomRate');
specialRate = document.getElementById('specialRate');
hotelName.textContent = hotel.name; // Write hotel name
roomRate.textContent = '$' + hotel.roomRate.toFixed(2); // Write room rate
specialRate.textContent = '$' + hotel.offerPrice(); // Write offer price
// PART TWO: CALCULATE AND WRITE OUT THE EXPIRY DETAILS FOR THE OFFER
var expiryMsg; // Message displayed to users
var today; // Today's date
var elEnds; // The element that shows the message about the offer ending
function offerExpires(today) {
// Declare variables within the function for local scope
var weekFromToday, day, date, month, year, dayNames, monthNames;
// Add 7 days time (added in milliseconds)
weekFromToday = new Date(today.getTime() + 7 * 24 * 60 * 60 * 1000);
// Create arrays to hold the names of days / months
dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
// Collect the parts of the date to show on the page
day = dayNames[weekFromToday.getDay()];
date = weekFromToday.getDate();
month = monthNames[weekFromToday.getMonth()];
year = weekFromToday.getFullYear();
// Create the message
expiryMsg = 'Offer expires next ';
expiryMsg += day + ' (' + date + ' ' + month + ' ' + year + ')';
return expiryMsg;
}
today = new Date(); // Put today's date in variable
elEnds = document.getElementById('offerEnds'); // Get the offerEnds element
elEnds.innerHTML = offerExpires(today); // Add the expiry message
// Finish the immediately invoked function expression
}());
|