JAC444: Dates Tim McKenna Dates, Calendars, and what year is this? §Java tries to take an OOD approach to “when is now?” §import java.util.*;

Slides:



Advertisements
Similar presentations
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 1 Abstract Classes and Interfaces.
Advertisements

CS 180 Recitation 9 / {06, 07} / Reminders Assignment 1 was due last night. Assignment 2 is available & due in 1 week. 10:00pm, Wednesday, September.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Confirmation Dialog Formatting Output.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 2 Getting Started with Java Structure of.
Processing Date and Time Date class Date currentTime = new Date(); DateFormat class The DateFormat class can be used to format date and time in a number.
Time & Date Representation in Java. Date class An object of type Date represents an instance in time Part of java.util.* (requires import statement) A.
CS 2511 Fall Features of Object Oriented Technology  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance.
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: IO *Standard Output *Formatting Decimal.
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
Java Programming, Second Edition Chapter Four Advanced Object Concepts.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
More Object Concepts Chapter 4.  Our class is made up of several students and each student has a name and test grades  How do we assign the variables.
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
Server-Side Scripting with JSP (2) ISYS 350. Java Array Examples of declaring an array: – int[] anArray = new int[10]; 10 elements index from 0 to 9 –
Chapter 14 Internationalization F Processing Date and Time –Locale –Date –TimeZone –Calendar and GregorianCalendar –DateFormat and SimpleDateFormat F Formatting.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 26 Internationalization.
Chapter 12: Internationalization Processing Date and Time Processing Date and Time  Locale  Date  TimeZone  Calendar and GregorianCalendar  DateFormat.
Objects and Classes Chapter 6 CSCI CSCI 1302 – Objects and Classes2 Outline Introduction Defining Classes for Objects Constructing Objects Accessing.
1 1 Abstract Classes and Interfaces. 22 Motivations You learned how to write simple programs to display GUI components. Can you write the code to respond.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 1 Chapter 13 Abstract Classes and Interfaces.
Copyright © 2012 Pearson Education, Inc. Chapter 3 Using Classes and Objects Java Software Solutions Foundations of Program Design Seventh Edition John.
COP-3330: Object Oriented Programming Flow Control May 16, 2012 Eng. Hector M Lugo-Cordero, MS.
Nic Shulver, Date and Time in JSP Surely it must be easy? Many calendars exist. The year 2013 (“Gregorian” or “Western”) is also:
CMRDB 靜宜大學行雲者研發基地 Java 日期時間函數 DateTime Method. 2 日期時間類別庫 ◎ java.util.*  java.util.Calendar  java.util.GregorianCalendar  java.util.TimeZone  java.util.SimpleTimeZone.
Chapter 14 Internationalization F Processing Date and Time –Locale –Date –TimeZone –Calendar and GregorianCalendar –DateFormat and SimpleDateFormat F Formatting.
Server-Side Scripting with JSP (2) ISYS 350. Java Array Examples of declaring an array: – int[] anArray = new int[10]; 10 elements index from 0 to 9 –
Garside, JAVA: First Contact, 2ed Java First Contact – 2 nd Edition Garside and Mariani Chapter 6 More Java Data Types.
1 G53SRP: Clocks and Time in Java Chris Greenhalgh School of Computer Science.
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
COMP201 Java Programming Topic 3: Classes and Objects Readings: Chapter 4.
Lab 1 Logbook ADT. OVERVIEW A monthly logbook consists of a set of entries, one for each day of the month.
More Object Concepts— Farrell, Chapter 4 Dr. Burns.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
Chapter 3 Objects and Classes. Objects Object – a data type with structure, state, and operations to access and manipulate state - an instance of a class.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 1 Chapter 13 Abstract Classes and Interfaces.
1 Chapter 20 Internationalization. 2 Objectives F To describe Java's internationalization features (§ 20.1). F To construct a locale with language, country,
BPJ444: Dates Peter Liu Tim McKenna Dates, Calendars, and what year is this? §Java tries to take an OOD approach to “when is now?” §import.
Java Util Package Prepared by, S.Amudha AP/SWE. Calendar 1.The abstract Calendar class provides a set of methods that allows you to convert a time in.
JAC444: Intro to Java Arrays and Vectors Tim McKenna
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
Utility classes 1.Vector class 2.Random class 3.Date class 4.Scanner.
Working with Date and Time ISYS 475. How PHP processes date and time? Traditional way: – Timestamp Newer and object oriented way: – DateTime class.
© Andy Wellings, 2004 Thread Priorities I  Although priorities can be given to Java threads, they are only used as a guide to the underlying scheduler.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 1 Chapter 15 Abstract Classes and Interfaces.
Working with Date ISYS 350.
Chapter 13 Abstract Classes and Interfaces
Chapter 13 Abstract Classes and Interfaces
Basic Utility Classes U Abd. Rohim, MT mailto:
Chapter 11 Abstract Classes and Interfaces
Chapter 14 Internationalization
Objects and Classes.
Java String and Date ISYS 350.
Exercise on Java Basics
CS170 ygao JAVA, C7.
Servlet Date Operations
Chapter 13 Abstract Classes and Interfaces
Java Date ISYS 350.
Exercise on Java Basics
Unit-2 Objects and Classes
Prepared by, S.Amudha AP/SWE
Chapter 12 Abstract Classes and Interfaces
Java Date ISYS 350.
Chapter 35 Internationalization
Applying OO Concepts Using Java
Using java libraries CGS3416 spring 2019.
Chapter 13 Abstract Classes and Interfaces Part 01
Java Date ISYS 350.
Java Date ISYS 350.
Presentation transcript:

JAC444: Dates Tim McKenna

Dates, Calendars, and what year is this? §Java tries to take an OOD approach to “when is now?” §import java.util.*; // get util package §Date class – represents a point in time §Calendar class – a general way to organize time §java.GregorianCalendar –a specific way to organize time.specific way to organize time

Date and Time ucurrent date and time (in milliseconds) after January 1, :00:00 GMT u long ms = System.currentTimeMillis( ) umilliseconds as a date & time object u java.util.Date date = new Date(); uDate is mostly deprecated because… uis a Date created at this moment here the same as one created in Australia?  same ms but different date/time to us uDate assumes local time zone!

GregorianCalendar uGregorianCalendar extends Calendar ucaptures ms timestamp and time zone u constructors can create current or other date u getTime( ) returns a Date object u get(Calendar.YEAR / MONTH / DATE / etc ) u set or add(Calendar.YEAR/etc, int ) u boolean gc1.after(gc2) or gc1.before(gc2) uExample: DateTime.java

GregorianCalendar caution §always follow one or more.set(Calendar.XXX) method calls with any.get(Calendar.XXX) call. §GregorianCalendar today = new GregorianCalendar(); // current date today.set(Calendar.HOUR_OF_DAY, 0); today.set(Calendar.MINUTE, 0); today.set(Calendar.SECOND, 0); today.get(Calendar.DATE); // update fields

GregorianCalendar alternative §see Joda-Time at §Stephen Colebourne is the Lead Technical Architect … see his presentation in a PDFStephen ColebournePDF §Joda-Time may be needed in applications that do a lot of date and time processing

GregorianCalendar utilities §Databrew in the bobjects package offers: §daysInterval() number of days difference between two local dates ignoring time of day. §timeInterval() – "days hh:mm:ss" difference §calendarInterval() – "yy-mm-dd hh:mm:ss" difference

Formatting Date and Time ujava.text.SimpleDateFormat - constructors - date formatting symbols - format( ) uonly works if set() was followed by get() uExample: FormatDateTime.java

Preset Formatters ujava.text.DateFormat - the parent class of SimpleDateFormat uDateFormat constants: SHORT, MEDIUM, LONG, FULL uDateFormat static methods : getDateInstance( ), getTimeInstance( ), getDateTimeInstance( ) retrieve normal format for that system uExample: DefaultFormats.java