ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming javascript dates.

Slides:



Advertisements
Similar presentations
Learn all about the year.
Advertisements

SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY
Prepositions of time In on at.
Reading Input from the Console eval function. variable = input("Enter a value: ") The value entered is a string. You can use the function eval to evaluate.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming cookies.
Session 8 JavaScript/Jscript: Objects Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
Chubaka Producciones Presenta :.
The Months and The Seasons Prepared by Claudia Doria and Terra Myers.
2012 CALENDAR. JANUARY 2012 Sunday 日 Monday 月 Tuesday 火 Wednesday 水 Thursday 木 Friday 金 Saturday 土
1 HCI 201 JavaScript - Part 1. 2 Static web pages l Static pages: what we have worked with so far l HTML tags tell the browser what to do with the content.
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt CalendarTime.
2012 JANUARY Sun Mon Tue Wed Thu Fri Sat
January 2012 Monday Tuesday Wednesday Thursday Friday Sat/ Sun / /8 14/15 21/22 28/
The days of the week Saturday Sunday Monday Tuesday Wednesday Thursday
P Pathophysiology Calendar. SundayMondayTuesdayWednesdayThursdayFridaySaturday January 2012.
© Oscar Nierstrasz ST — xxx X.1 Class Methods - Class Instance Variables  Classes (Packet class) represents class (Packet).  Class instance variables.
Chicas, este calendario si es pa' nosotras !!!!!.
MONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSATURDAYSUNDAY WEEK WEEK WEEK WEEK WEEK CALENDAR PROJECT.
MATHEMATICS Time – Dates, Calendars and Timetables.
JavaScript Events and Event Handlers 1 An event is an action that occurs within a Web browser or Web document. An event handler is a statement that tells.
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
2007 Monthly Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation. If you’d like to change.
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
CONFIDENTIAL1 Good Afternoon! Today we will be learning about Temperature, changes, & negative numbers Let’s warm up : Complete the conversion tables:
What day is today? What`s the date?. Sunday Monday Tuesday Wednesday Thursday Friday Saturday What day is today?
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Includes and Dates.
VOCABULARY Vacation Review May HFW List 1 Pronounce the following words: things always day become nothing stays everything.
The Quiz in Green school. She sells sea hells on the sea shore. A black cat sat on a mat and ate a fat rat.
Keeping it Neat: Functions and JavaScript Source Files Chapter 7.
WORD JUMBLE. Months of the year Word in jumbled form e r r f b u y a Word in jumbled form e r r f b u y a february Click for the answer Next Question.
Click the button to begin. 12:25 What time does this clock show? 5:00 4:00.
DATE POWER 2 INCOME JANUARY 100member X 25.00P2, FEBRUARY 200member X 25.00P5, MARCH 400member X 25.00P10, APRIL 800member.
Non Leap YearLeap Year DateDay NumberMod 7Day NumberMod 7 13-Jan Feb Mar Apr May Jun Jul
By Monica Hilgemann Second Grade Teacher
2011 Calendar Important Dates/Events/Homework. SunSatFriThursWedTuesMon January
What can we do in English?. Can you count in English? Count from one to ten and vice versa. Count from ten to twenty and vice versa. Can you continue.
Time. Here is a clock. Clocks show us time. This is an hourglass. Hourglasses show us time, too. Click here.
Making Pages Dynamic Chapter 8 JavaScript for the WWW.
VOCABULARY Vacation Review May HFW List 1 Read aloud the following words: things always day become nothing stays everything.
The Calendar.
July 2007 SundayMondayTuesdayWednesdayThursdayFridaySaturday
CONFIDENTIAL1 Good Afternoon! Today we will be learning about Calendar and Years Let’s warm up : Complete the conversion tables: Hours478 Minutes 1) Calculate.
EVERY WEEK Every week has seven days, See how many you can say.
Dictation practice 2nd Form Ms. Micaela-Ms. Verónica.
McDonald’s Kalender 2009.
McDonald’s Kalender 2009.
Year 2 Autumn Term Week 12 Lesson 1
13-block rotation schedule
1   1.テキストの入れ替え テキストを自由に入れ替えることができます。 フチなし全面印刷がおすすめです。 印刷のポイント.
January MON TUE WED THU FRI SAT SUN
January MON TUE WED THU FRI SAT SUN
McDonald’s Kalender 2009.
January MON TUE WED THU FRI SAT SUN
2300 (11PM) September 21 Blue line is meridian..
McDonald’s calendar 2007.
Year 2 Autumn Term Week 12 Lesson 1
1 - January - Sun Mon The Wed Thu Fri Sat
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
February 2007 Note: Source:.
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
McDonald’s calendar 2007.
Production Month Sun Hours K Monthly Kwh Tou Peak Value After Kwh
Habitat Changes and Fish Migration
2015 January February March April May June July August September
Habitat Changes and Fish Migration
Presentation transcript:

ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming javascript dates

ECA 225 Applied Interactive Programming Date( ) constructor to create a new Date object use the new operator this instance of a Date( ) object contains the current date and time, the exact date and time, to the millisecond, it was created var now = new Date( );

ECA 225 Applied Interactive Programming Date( ) constructor cont … if we use the alert( ) method to display the current date we get a value similar to: var now = new Date( ); alert( now ); Thu Sep 25 15:28:20 EDT 2003

ECA 225 Applied Interactive Programming Date( ) methods  the Date( ) object can be broken down into its individual pieces using a variety of Date( ) methods  because the variable name we created ( now ) holds a reference to a Date( ) object, we can use dot notation to access methods

ECA 225 Applied Interactive Programming Date( ) methods cont …  Date.getDate( )  returns the numeric day of the month var now = new Date( ); var d = now.getDate( ); // returns day of month alert( d )

ECA 225 Applied Interactive Programming Date( ) methods cont …  Date.getDay( )  returns the numeric day of the week, 0 – 6 var now = new Date( ); var d = now.getDay( ); // returns day of week alert( d )

ECA 225 Applied Interactive Programming Date( ) methods cont …  to return a string representation of the day of the week, use an array var now = new Date( ); var days = new Array( “Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday” ); alert( days[ now.getDay( ) ] ) ;

ECA 225 Applied Interactive Programming Date( ) methods cont …  Date.getMonth( )  returns the numeric month, 0 – 11 var now = new Date( ); var month = now.getMonth( ); // returns month alert( month )

ECA 225 Applied Interactive Programming Date( ) methods cont …  to return a string representation of the month, use an array var now = new Date( ); var month = new Array( “January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December” ); alert( month[ now.getMonth( ) ] ) ;

ECA 225 Applied Interactive Programming Date( ) methods cont …  Date.getFullYear( )  returns the numeric 4-digit year var now = new Date( ); var y4 = now.getFullYear( ); // returns 4-digit year alert( y4 )

ECA 225 Applied Interactive Programming Date( ) methods cont …  Date.getYear( )  returns the numeric 2-digit year, pre-2000 var now = new Date( ); var y2 = now.getYear( ); // returns 2-digit year alert( y2 )

ECA 225 Applied Interactive Programming Date( ) methods cont …  Date.getHours( )  returns the numeric hours, 0 – 23 var now = new Date( ); var h = now.getHours( ); // returns hours, 0 – 23 alert( h )

ECA 225 Applied Interactive Programming Date( ) methods cont …  Date.getMinutes( )  returns the numeric minutes, 0 – 59 var now = new Date( ); var m = now.getMinutes( ); // returns hours, 0 – 59 alert( m )

ECA 225 Applied Interactive Programming Date( ) methods cont …  Date.getSeconds( )  returns the numeric seconds, 0 – 59 var now = new Date( ); var s = now.getSeconds( ); // returns seconds, 0 – 59 alert( s )

ECA 225 Applied Interactive Programming Date( ) methods cont …  Date.getMilliseconds( )  returns the numeric milliseconds, 0 – 999 var now = new Date( ); var ms = now.getMilliseconds( ); // returns 0 – 999 alert( ms )

ECA 225 Applied Interactive Programming local time  the date and time to which a Date( ) object is set is based upon the local time of the user’s computer, not the server  scripts read the clock setting of the user’s computer  to make time comparisons between a user’s local time and another time zone a standard reference point is needed

ECA 225 Applied Interactive Programming Greenwich Mean Time GMT Uzbekistan +5 Ohio – 5 IDL

ECA 225 Applied Interactive Programming GMT / UTC  another name for GMT is UTC, Coordinated Universal Time  many JavaScript methods have 2 versions  one for local time  one for GMT or UTC

ECA 225 Applied Interactive Programming milliseconds  basic unit of measuring JavaScript time is one millisecond, or 1/1000 th of a second  JavaScript maintains date information in the form of a count, in milliseconds, since 1 January, 1970, at midnight, in Greenwich, England  midnight, 1 January, 1970 is known as the Unix Epoch

ECA 225 Applied Interactive Programming Date( ) methods cont …  Date.getTime( )  returns the number of milliseconds since the Unix Epoch, midnight, 1 January, 1970 var now = new Date( ); var ts = now.getTime( ); // returns the number // of milliseconds since midnight, 1 Jan, 1970 alert( ts )

ECA 225 Applied Interactive Programming comparing Date( ) objects  to compare different Date( ) objects, return the number of milliseconds that have passed for each, since the Unix Epoch  compare the milliseconds – the one which is smaller in size occurred first

ECA 225 Applied Interactive Programming creating Date( ) objects to create Date( ) object to a specific day and time, such as a future date  new Date( “Month dd, yyyy hh:mm:ss “ );  new Date( “Month dd, yyyy” );  new Date( yy,mm,dd,hh,mm,ss );  new Date( yy,mm,dd );  new Date( milliseconds );

ECA 225 Applied Interactive Programming  to create a Date( ) object holding the values for New Year’s Day, midnight, 2013 creating Date( ) objects cont … var newYear = new Date(2013,00,01,00,00,00) var newYear = new Date( “January :00:00 “ );

ECA 225 Applied Interactive Programming Date( ) set methods  JavaScript’s Date( ) set methods are used to set or reset the values associated with the object  set methods return the new date in milliseconds var date1 = new Date( ); alert ( date1 ); date1.setFullYear( 2007 ); alert ( date1 );

ECA 225 Applied Interactive Programming Date( ) set methods cont …  Date.setDate( )  set the day, given a number between 1 – 31 var date1 = new Date( ); alert ( date1 ); date1.setDate( 13 ); alert ( date1 );

ECA 225 Applied Interactive Programming Date( ) set methods cont …  Date.setMonth( )  set the month, given a number between 0 – 11 var date1 = new Date( ); alert ( date1 ); date1.setMonth( 3 ); alert ( date1 );

ECA 225 Applied Interactive Programming Date( ) set methods cont …  Date.setFullYear( )  set the year, given a 4 digit year var date1 = new Date( ); alert ( date1 ); date1.setFullYear( 2013 ); alert ( date1 );

ECA 225 Applied Interactive Programming Date( ) set methods cont …  Date.setYear( )  set the year, given a 2 or 4 digit year var date1 = new Date( ); alert ( date1 ); date1.setYear( 2013 ); alert ( date1 );

ECA 225 Applied Interactive Programming Date( ) set methods cont …  Date.setHours( )  set the hour, given a number between 0 – 23 var date1 = new Date( ); alert ( date1 ); date1.setHour( 13 ); alert ( date1 );

ECA 225 Applied Interactive Programming Date( ) set methods cont …  Date.setMinutes( )  set the minutes, given a number between 0 – 59 var date1 = new Date( ); alert ( date1 ); date1.setMinutes( 33 ); alert ( date1 );

ECA 225 Applied Interactive Programming Date( ) set methods cont …  Date.setSeconds( )  set the seconds, given a number between 0 – 59 var date1 = new Date( ); alert ( date1 ); date1.setSeconds( 33 ); alert ( date1 );

ECA 225 Applied Interactive Programming Date( ) set methods cont …  Date.setMilliseconds( )  set the milliseconds, given a number between 0 – 999 var date1 = new Date( ); alert ( date1 ); date1.setMilliseconds( 613 ); alert ( date1 );

ECA 225 Applied Interactive Programming Date( ) set methods cont …  Date.setTime( )  set a date, given the number of milliseconds since 1 January 1970 var date1 = new Date( ); alert ( date1 ); date1.setTime( ); alert ( date1 );

ECA 225 Applied Interactive Programming Date( ) set methods cont …  a construction used to set a Date( ) object to a specific distance in the future: var date1 = new Date( ); alert ( date1 ); date1.setFullYear( date1.getFullYear( ) + 1 ); alert ( date1 );

ECA 225 Applied Interactive Programming Date & Time Arithmetic  the millisecond is the JavaScript basic unit of time  precise time calculations involving the addition or subtraction of dates should be performed using milliseconds

ECA 225 Applied Interactive Programming Date & Time Arithmetic cont …  creation of variables holding the number of milliseconds in a minute, hour, day and week may be useful var one_minute = 60 * 1000; var one_hour = one_minute * 60; var one_day = one_hour * 24; var one_week = one_day * 7;

ECA 225 Applied Interactive Programming.js library  the previous variables, plus the arrays holding the names of the days and months, can be placed in an external JavaScript file  the external file, or library, can then be referenced by any page, similar to an external style sheet  external files must end with a.js extension

ECA 225 Applied Interactive Programming.js library cont …  the reference to the external.js file will look like:  the tag MUST have a corresponding closing tag  avoid putting any other code inside the opening and closing tags  place reference inside tags

ECA 225 Applied Interactive Programming.js library cont …  the server must be configured correctly to serve an external.js file  CAUTION: using an external.js file does not hide your code  do not place any confidential or sensitive material inside a.js file

ECA 225 Applied Interactive Programming Date & Time Arithmetic cont …  EG, to create a date exactly 26 weeks from the current date: var date1 = new Date( ); alert ( date1 ); date1.setTime( date1.getTime( ) + one_week * 26 ); alert ( date1 );

ECA 225 Applied Interactive Programming Date & Time Arithmetic cont …  to set the expiration date for a cookie to 6 months hence or var exp = new Date( ); exp.setTime( exp.getTime( ) + one_week * 26 ); var exp = new Date( ); exp.setMonth( exp.getMonth( ) + 6 );