Working with Date ISYS 350.

Slides:



Advertisements
Similar presentations
Dates and Times SAS Date, Time and Date- Time Formats.
Advertisements

Server-Side Scripting with JSP (2) ISYS 350. Post Back A postback is call to the same page that the form is on. In other words, the contents of the form.
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
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.
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.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: IO *Standard Output *Formatting Decimal.
Cupertino, CA, USA / September, 2000First ICU DeveloperWorkshop1 Date/Time/Number Formatting Alan Liu Globalization Center of Competency IBM Emerging Technology.
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 –
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.
Mark Dixon Page 1 3 – Web applications: Server-side code (JSP)
Server-Side Scripting with Java Server Page, JSP ISYS 350.
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.
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.*;
Nic Shulver, Date and Time in JSP Surely it must be easy? Many calendars exist. The year 2013 (“Gregorian” or “Western”) is also:
Chapter 14 Internationalization F Processing Date and Time –Locale –Date –TimeZone –Calendar and GregorianCalendar –DateFormat and SimpleDateFormat F Formatting.
Dates and Times. Slide 2 Introduction to Dates and Times (1) The DateTime data type is used to store dates and times There is a date part There is a time.
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 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.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Working with Date and Time ISYS 475. How PHP processes date and time? Traditional way: – Timestamp Newer and object oriented way: – DateTime class.
Date Dimension: Past & Future in One Script Steve Wake, BI Developer, Chipotle.
JSP java server pages.
Java Programming Static Methods.
Java Class and Servlet ISYS 350.
JavaScript.
Basic Utility Classes U Abd. Rohim, MT mailto:
14 Shipping Time App Using Dates and Timers
Tutorial 14 – Shipping Time Application Using DateTimes and Timers
Built-in Functions.
Chapter 14 Internationalization
Chapter 2 Elementary Programming
Quiz # 02 Design a data type Date to hold date
Java String and Date ISYS 350.
JavaScript Arrays Date
SQL – Dates and Times.
CSC141 Computer Science I Zhen Jiang Dept. of Computer Science
CS170 ygao JAVA, C7.
Servlet Date Operations
Time Revision.
Java Date ISYS 350.
Server-Side Scripting with Java Server Page, JSP
Server-Side Scripting with Java Server Page, JSP
Formatting Output.
BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES
Working with DateTime Data
When will Eclipses occur ?
Time is not on my side.
Prepared by, S.Amudha AP/SWE
Forms Data Entry and Capture
Java Date ISYS 350.
Chapter 35 Internationalization
Prepared By: Deborah Becker
Introduction to Programming with Python
HTML5 Demo ISYS 350.
Chapter 6.
Java Date ISYS 350.
Lesson Quizzes Standard Lesson Quiz
HTML Forms What are clients? What are servers?
The Web Wizard’s Guide To JavaScript
Маңғыстау облысы, Маңғыстау ауданы, Өтес селосы
Java Date ISYS 350.
Temporal Data Part V.
Web Forms.
Working with dates and times
Presentation transcript:

Working with Date ISYS 350

Java Date Processing: Date Class Define a date object: Date myDate; Define a date object with the current date: Date currentDate = new Date(); getTime method: return the date in milliseconds since 1/1/1900 Note: A day has 24*60*60*1000 milliseconds.

Java Date Processing: DateFormat class DateFormat class is used to define a date format to display a date object or parsing a date/time string to create a date object. Define a date format: DateFormat formatter = new SimpleDateFormat("MM/dd/yy"); To print a data object: out.print("Current date is: " + formatter.format(currentDate)); To parse a date string: myDate=formatter.parse(request.getParameter("txtDate"));

Import Java Class Example: Display Current Date Time Import java.util.Date <%@page import="java.util.Date"%> Define a Date type variable: Date currentDate = new Date(); Display in textbox using JSP expression: <p>The time is: <input type="text" name="num2" size="20" value="<%=currentDate%>"></p>

Date Format Import class: Define a format: <%@page import="java.text.DateFormat"%> Define a format: SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy"); Convert: Example: Display a date with date format: String displayDate = formatter.format(currentDate); <% Date currentDate = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); String displayDate = formatter.format(currentDate); %> <p>The time is: <input type="text" name="num2" size="20" value="<%=currentDate%>"></p><br> <p>The time is: <input type="text" name="num2" size="20" value="<%=displayDate%>">

Define Date Format Letter   Date or Time Component   Presentation       Examples G        Era designator              Text                AD y        Year                        Year                1996;    96 M        Month in year                Month               July; Jul; 07 w        Week in year                Number               27 W        Week in month                Number               2 D        Day in year                Number               189 d        Day in month                Number               10 F        Day of week in month        Number               2 E        Day in week                Text               Tuesday; Tue a        Am/pm marker                Text               PM H        Hour in day (0-23)        Number               0 k        Hour in day (1-24)        Number               24 K        Hour in am/pm (0-11)        Number               0 h        Hour in am/pm (1-12)        Number               12 m        Minute in hour            Number               30 s        Second in minute            Number               55 S        Millisecond                 Number               978 z        Time zone                   General time zone   Pacific Standard Time; PST; GMT-08:00 Z        Time zone                  RFC 822 time zone   -0800

Calculating Days between Current Date and Entered Date Using the getTime() method <form name="dateForm" method="get" action="computeDate.jsp"> Enter a date: <input type="text" name="txtDate" /><br><br> <input type="submit" value="compute Date" name="btnSubmit" /> </form>

computeDate.jsp <% Date currentDate = new Date(); Date myDate; DateFormat formatter = new SimpleDateFormat("MM/dd/yy"); myDate=formatter.parse(request.getParameter("txtDate")); out.print(currentDate +"<br>"); out.print("Current date is: " + formatter.format(currentDate)+"<br>"); out.print("Entered date is: " + formatter.format(myDate)+"<br>"); out.print ("Days between = " + (currentDate.getTime()-myDate.getTime())/(24*60*60*1000)+"<br>"); DateFormat yearFormat=new SimpleDateFormat("yyyy"); DateFormat monthFormat=new SimpleDateFormat("MM"); DateFormat weekDayFormat=new SimpleDateFormat("E"); DateFormat hourFormat=new SimpleDateFormat("H"); out.print(yearFormat.format(currentDate)+"<br>"); out.print(monthFormat.format(currentDate)+"<br>"); out.print(weekDayFormat.format(currentDate)+"<br>"); out.print(hourFormat.format(currentDate)+"<br>"); double hour; hour=Double.parseDouble(hourFormat.format(currentDate)); %>