Strings and Dates in JavaScript

Slides:



Advertisements
Similar presentations
Intro to Scala Lists. Scala Lists are always immutable. This means that a list in Scala, once created, will remain the same.
Advertisements

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 –
The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.
The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
JavaScript, Fourth Edition
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
M. Taimoor Khan Javascript Objects  Every data-type defined in Javascript is an object  It has a class definition for.
1 JavaScript
XP Tutorial 2 New Perspectives on JavaScript, Comprehensive1 Working with Operators and Expressions Creating a New Year’s Day Countdown Clock.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
Chapter 5 Murach's JavaScript and jQuery, C1© 2012, Mike Murach & Associates, Inc.Slide 1.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
Introduction to Computing Science and Programming I
AP CSP: Cleaning Data & Creating Summary Tables
CHAPTER 10 JAVA SCRIPT.
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Regular Expressions 'RegEx'.
Organize your code with MVC
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
JavaScript Objects.
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Modern JavaScript Develop And Design
SEEM4570 Tutorial 05: JavaScript as OOP
JavaScript Syntax and Semantics
Introduction to JavaScript
Introduction to JavaScript
© 2015, Mike Murach & Associates, Inc.
A second look at JavaScript
Organize your code with MVC
Class07 PHP: loops MIS 3501 Jeremy Shafer Department of MIS
Date Functions Farrokh Alemi, Ph.D.
Form Validation (with jQuery, HTML5, and CSS)
JavaScript and the DOM MIS 2402 Jeremy Shafer Department of MIS
Numbers, strings and dates in JavaScript
An Introduction to Animation
MIS JavaScript and API Workshop (Part 2)
An Introduction to JavaScript
Learning VB2005 language (basics)
Programming Control Structures with JavaScript Part 2
Getting started with jQuery
A Useful Footnote Martha Cox Population Health Research Unit Community Health & Epidemiology Dalhousie University Good morning. We've all had this happen:
For this assignment, copy and past the XHTML to a notepad file with the .html extension. Then add the code I ask for to complete the problems.
Sending a text message (and more)
An introduction to jQuery
Conditional Statements with JavaScript
Midterm Exam Information
Loops and Arrays in JavaScript
JavaScript objects, functions, and events
Introduction to JavaScript
February , 2009 CSE 113 B.
Introduction to JavaScript
An introduction to jQuery
Introduction to JavaScript
MVC – Model View Controller
Getting started with jQuery
Programming Control Structures with JavaScript
An introduction to jQuery
Introduction to AJAX and JSON
Form Validation (with jQuery, HTML5, and CSS)
The Web Wizard’s Guide To JavaScript
Introduction to JavaScript
JavaScript Session III
Working with dates and times
JavaScript and the DOM MIS 2402 Maxwell Furman Department of MIS
Presentation transcript:

Strings and Dates in JavaScript MIS 2402 Maxwell Furman Department of MIS Fox School of Business Temple University

Let’s talk about … Chapter 13 Last class we saw that “Math” and “Number” are JavaScript objects. Is Math.PI a property or a method? Is Math.random() a property or a method? How can you easily distinguish between properties and methods? Are strings and dates objects too?

Agenda Review last week's challenge Methods and Properties of Strings Representing Dates in Javascript Exam 2 review / lab period

Strings What will be the value of result_1?

Examples of methods of String objects What will be the value of each result variable?

Examples of methods of String objects (continued) What would be the advantage to converting user-provided data to all upper or lower case?

Reflection: While these individual string functions may not seem impressive, they can be used to parse and manipulate text. Used together with functions, conditional statements and loops to do elaborate things. See: https://www.masswerk.at/elizabot/

Date and time Notice the new operator here. JavaScript Date objects can only be instantiated by calling JavaScript Date as a constructor: calling it as a regular function (i.e. without the new operator) will return a string rather than a Date object. Unlike other JavaScript object types, JavaScript Date objects have no literal syntax… that is, you *must* use the new operator to create a Date object.

Create a Date object by specifying date parts

How to create a Date object by copying another Date object Some unexpected results when specifying a date string

The formatting methods of a Date object

The get methods of a Date object

The set methods of a Date object

Putting it together… A common programming challenge is to perform simple date "math" on a value. So for example, given that you have a certain date, what date will it be three hours from then? Or - if today is the 27th, what month will it be in two days? There are many ways of doing this, but one simple way is just combine a get and set call. //First, start with a particular time var date = new Date(); //Add two hours date.setHours(date.getHours() + 2); //Go back 3 days date.setDate(date.getDate() - 3); //One minute ago... date.setMinutes(date.getMinutes() - 1);

Let’s give this a try… Use countdown.zip provided by your instructor. Use Chrome Developer tools to set a breakpoint and step through the code. Observe how dates and strings are manipulated. Pro tip! You can avoid stepping into jQuery source code with “blackboxing” See: https://developer.chrome.com/devtools/docs/blackboxing