The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.

Slides:



Advertisements
Similar presentations
Chapter 7 JavaScript: Introduction to Scripting. Outline Simple Programs Objects and Variables Obtaining User Input with prompt Dialogs – –Dynamic Welcome.
Advertisements

The Web Wizards Guide To JavaScript Chapter 3 Working with Forms.
Lesson 4: Formatting Input Data for Arithmetic
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
Computer Science 103 Chapter 3 Introduction to JavaScript.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
HTML Comprehensive Concepts and Techniques Second Edition Project 8 Integrating JavaScript with HTML.
Lecture 1 Term 2 9/1/12 1. Objects You normally use the “.” Operator to access the value of an object’s properties. The value on the left of the “.” should.
Tutorial 11 Working with Operators and Expressions
The Information School of the University of Washington Oct 20fit programming1 Programming Basics INFO/CSE 100, Fall 2006 Fluency in Information Technology.
JavaScript Objects Objects – JavaScript is an object-based language Has built-in objects we will use – You can create your own objects We concentrating.
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.
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 12.
The Web Wizard’s Guide To JavaScript Chapter 1 JavaScript Basics.
Scripting Languages.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Extracting the System Date  Built-in Date() object  Can be manipulated only by creating a new object instance  var variable = new object  var birthDay.
UNIT 5 FUNCTIONS, OBJECTS, CONDITIONS, AND LOOPS.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 6. Functions and Objects I - 1
Database-Driven Web Sites, Second Edition1 Chapter 3 INTRODUCTION TO CLIENT-SIDE SCRIPTS.
1 CLIENT-SIDE SCRIPTS. Objectives 2 Learn how to reference objects in HTML documents using the HTML DOM and dot syntax Learn how to create client-side.
The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.
JavaScript: Objects Outline 12.1 Introduction 12.2 Thinking About Objects 12.3 Math Object 12.4 String Object Fundamentals of Characters and Strings.
1 Introduction to Javascript Peter Atkinson. 2 Objectives To understand and use appropriately some of the basic elements of Javascript: –alert and prompt.
Integrating JavaScript and HTML5 HTML5 & CSS 7 th Edition.
Working with background, images and date object Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
JavaScript, Fourth Edition
1 JavaScript 1. 2 Java vs. JavaScript Java –Is a high level programming language –Is platform independent –Runs on a standardized virtual machine.
Adobe GoLive Edit and FTP your web pages to a web server.
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
ALBERT WAVERING BOBBY SENG. Week 5: More JavaScript  Quiz  Announcements/questions.
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
Lecture 9 The Basics of JavaScript Boriana Koleva Room: C54
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Copyright ©2005  Department of Computer & Information Science Beginning DHTML: Working with Browser Objects.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
The Web Wizard’s Guide To JavaScript Chapter 7 Cookies: Maintaining State.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript. JavaScript is the programming language of HTML and the Web. Easy to learn One of the 3 languages of all developers MUST learn: 1. HTML to.
JS1-1 Introduction to JavaScript (JavaScript 1) Xingquan (Hill) Zhu
The Web Wizard’s Guide To JavaScript Chapter 3 Working with Forms.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
XP Tutorial 2 New Perspectives on JavaScript, Comprehensive1 Working with Operators and Expressions Creating a New Year’s Day Countdown Clock.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 13.
Tutorial 11 1 JavaScript Operators and Expressions.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 12 - JavaScript: Objects Outline 12.1 Introduction 12.2 Thinking About Objects 12.3 Math Object.
Chapter 9. An event-driven, object-based programming language that provides various types of functionality to pages. Object based: it is a language that.
Basic Objects. Math Object  Math.cos( x ), x in radians  Math.sqrt ( x )  Math.pow ( x, y )  Math.ceil( x )  etc.
JavaScript Non Primitive Datatype
Chapter 6 JavaScript: Introduction to Scripting
Java Script.
WEB APPLICATION PROGRAMMING
Introduction to Scripting
JavaScript Syntax and Semantics
Introduction to JavaScript
JavaScript.
BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES
INFO/CSE 100, Spring 2005 Fluency in Information Technology
The Web Wizard’s Guide To JavaScript
INFO/CSE 100, Spring 2006 Fluency in Information Technology
JavaScript: Introduction to Scripting
The Web Wizard’s Guide To JavaScript
Strings and Dates in JavaScript
Presentation transcript:

The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times

Chapter Objectives To understand JavaScript’s Date object To learn how to add a clock to a Web page To find out how to display the time and date in any format you like To see how to add a greeting to a Web page that changes with the time of day To learn how to add a time-sensitive greeting to your Web page clock To discover how to perform calculations based on dates

The Date Object JavaScript contains a set of core objects, including the Date object, that exist independently of any host environment such as a Web browser. To use the Date object, you first create an instance of it and then apply a method to obtain date and time information. Var currentDate = new Date();

Methods for the Date Object getDate() getDay() getFullYear() getHours() getMilliseconds() getMinutes() getMonth() getSeconds() getTime() getYear() toLocaleString()

Creating a simple clock Basic Clock <!-- function showTime(){ /* Callout: A new Date() object is created and stored in a variable. */ var now = new Date(); /* Callout: the toLocaleString() method of the Date object converts the date to a text format used in the visitor's location. */ document.clock.face.value = now.toLocaleString(); } //--> A Very Basic JavaScript Clock

Creating a Better Clock To create customized presentations of the time, you obtain the current hour, minute, and seconds using methods of the Date object. These values can be stored as variables and then concatenated (joined together) to create a string of text to express the time.

Creating Dynamic Greetings It is possible to vary the information displayed on your Web page according to the time or date. If code exists in the HEAD to test for the time of day, you can create variable content in the BODY using the document.write() method.

Text Fields vs. document.write() Use document.write() for content that will not change during the visitor’s session. Use text fields for content that requires updating during the visitor’s session, such as time of day.

Date Mathematics JavaScript’s Math object is a built-in calculator. To perform math operations on information obtained from text fields, you first convert the values to numbers using the parseInt() or parseFloat() function. Date mathematics allows you to create countdown pages to important events.

Differences in the two objects Date Object – an instance is created of it by creation in code var currentDate = new Date(); Math object – Static, which means that we never creates an instance of the object Math.abs (x), Math.floor(x), Math.max(x,y) Math.min(x,y), Math.random()