Java String and Date ISYS 350.

Slides:



Advertisements
Similar presentations
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.
Advertisements

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 –
Server-Side Scripting with Java Server Page, JSP ISYS 350.
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.*;
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.
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.
Tutorial 11 1 JavaScript Operators and Expressions.
Working with Date and Time ISYS 475. How PHP processes date and time? Traditional way: – Timestamp Newer and object oriented way: – DateTime class.
IMS 3253: Dates and Times 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Date and Time Data Turning Strings into.
Lecture 4 CS140 Dick Steflik. Reading Keyboard Input Import java.util.Scanner – A simple text scanner which can parse primitive types and strings using.
JSP java server pages.
Working with Date 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
Decision Structure ISYS 350.
Built-in Functions.
Chapter 14 Internationalization
JavaScript Arrays Date
© Copyright 2016, Fred McClurg All Rights Reserved
SQL – Dates and Times.
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
Starting JavaProgramming
Java for Teachers Intermediate
Working with DateTime Data
Time is not on my side.
Work with Data and Decision Structure
Prepared by, S.Amudha AP/SWE
sscanf()- string scan function
Date Functions Farrokh Alemi, Ph.D.
Sudeshna Sarkar 7th March 2017
Java Date ISYS 350.
        CALCULATING THE MATURITY DATE 1 2 CALCULATING INTEREST
Chapter 35 Internationalization
Prepared By: Deborah Becker
Basics.
Introduction to Programming with Python
HTML5 Demo ISYS 350.
Java: Variables, Input and Arrays
Java Date ISYS 350.
The Web Wizard’s Guide To JavaScript
Java Date ISYS 350.
Temporal Data Part V.
Working with dates and times
Presentation transcript:

Java String and Date ISYS 350

String Class Methods https://www.tutorialspoint.com/java/java_strings.htm

Testing if two strings are equal The equals() or equalsIgnoreCase method should be used to determine whether two objects have the same values. String string1 = "foo"; String string2 = "Foo"; if (string1==string2) //if (string1.equals(string2)) //if (string1.equalsIgnoreCase(string2)) { out.println("The two strings are equal."); } else out.println("The two strings are not equal.");

Split method It returns the array of strings computed by splitting this string around matches of the given character (regular expression). Example: <% String commaDelimited = "90,56,75,90,75,90,88,100"; String [] dataArray; String myStr=""; dataArray=commaDelimited.split(","); for (int i=0;i<=dataArray.length-1;i++) { myStr+=dataArray[i]; } %> <p><%=myStr%></p>

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

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 to 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);

Code Example <% 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> <p>The time is: <input type="text" name="num2" size="20" value="<%=displayDate%>"></p> <p>The time is: <input type="text" name="num2" size="20" value="<%=formatter.format(currentDate)%>"></p>

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

Example of Date Format: Sat, April 29, 2017 SimpleDateFormat formatter = new SimpleDateFormat("E, MMMM dd, yyyy");

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" value="" /><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"); out.print(yearFormat.format(currentDate)+"<br>"); out.print(monthFormat.format(currentDate)+"<br>"); out.print(weekDayFormat.format(currentDate)+"<br>"); %>