Типы для времени и денег. Дата и время презентация

Содержание

Среднее время по Гринвичу

Слайд 1IX. Типы для времени и денег
1. Дата и время




Слайд 2Среднее время по Гринвичу


Слайд 3Всемирное время


Слайд 4Всемирное координированное время


Слайд 5Секунда координации


Слайд 6

База данных tz и часовые зоны


Слайд 7База данных tz database


Слайд 8Часовые зоны


Слайд 9

Сезонный перевод времени


Слайд 10Сезонный перевод времени


Слайд 11Переход на летнее время


Слайд 12

Время у нас


Слайд 13Федеральный закон об исчислении времени


Слайд 14

Получение и измерение времени


Слайд 15Получение и измерение времени
package java.lang;

public final class System {

public

static long currentTimeMillis()
public static long nanoTime()
}

C



Слайд 16Получение времени
public class TimeObtainDemo {

public static void main(String[] args)

{

DateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss z");
long current = System.currentTimeMillis();

System.out.println("Current time in milliseconds since 01.01.1970: " + current);
System.out.println(formatter.format(current));
}
}


Current time in milliseconds since 01.01.1970: 1326621450000
2012.01.15 16:57:30 NOVT



Слайд 17Измерение времени
public class TimeMeasureDemo {

private static void doSomething() throws

InterruptedException {

for (int i = 0; i < 5; i++) {

System.out.println("Doing something...");
Thread.sleep(1000);
}
}

public static void main(String[] args) throws InterruptedException {

long startTime = System.currentTimeMillis();

doSomething();

long endTime = System.currentTimeMillis();

long totalTime = endTime - startTime;
System.out.println("It took " + (totalTime / 1000)
+ " seconds to do something");
}
}


Doing something...
Doing something...
Doing something...
Doing something...
Doing something...
It took 5 seconds to do something



Слайд 18Абсолютность времени
public class AbsoluteDemo {

public static void main(String[] args)

{

DateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss z Z");

long zero = 0;

formatter.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
System.out.println(formatter.format(zero));

formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println(formatter.format(zero));

formatter.setTimeZone(TimeZone.getTimeZone("Asia/Novosibirsk"));
System.out.println(formatter.format(zero));
}
}


1969.12.31 16:00:00 PST -0800
1970.01.01 00:00:00 GMT +0000
1970.01.01 07:00:00 NOVT +0700



Слайд 19

Класс java.util.Date


Слайд 20Класс java.util.Date
package java.util;

public class Date implements Serializable, Cloneable, Comparable {

private transient long fastTime;

public Date() {
this(System.currentTimeMillis() );
}

public Date(long date) {
fastTime = date;
}

public long getTime()
public boolean after(Date when)
public boolean before(Date when)

public Object clone()
public int compareTo(Date anotherDate)
public boolean equals(Object obj)
public String toString()
}

C

fastTime

fastTime

System.currentTimeMillis()



Слайд 21Получение объекта класса Date
public class DateObtainDemo {

public static void

main(String[] args) {

DateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss z");
Date current = new Date();


System.out.println("Current time in milliseconds since 01.01.1970: " + current.getTime());
System.out.println(formatter.format(current));
}
}


Current time in milliseconds since 01.01.1970: 1326621450000
2012.01.15 16:57:30 NOVT



Слайд 22

Часовые зоны


Слайд 23Где хранится информация о часовых зонах?


Слайд 24Обновление информации о часовых зонах


Слайд 25Часовые зоны


Слайд 26Доступные часовые зоны
public class TimeZoneAvailableDemo {

public static void main(String[]

args) {

String[] IDs = TimeZone.getAvailableIDs();

for (String id : IDs) {
System.out.println(id);
}
}
}

Etc/GMT+12
Etc/GMT+11
Pacific/Midway
Pacific/Niue
Pacific/Pago_Pago
Pacific/Samoa
US/Samoa
America/Adak
America/Atka
Etc/GMT+10
HST
Pacific/Honolulu
...
Pacific/Apia
Pacific/Enderbury
Pacific/Fakaofo
Pacific/Tongatapu
Etc/GMT-14
Pacific/Kiritimati



Слайд 27Получение информации о часовой зоне
public class TimeZoneDemo {

public static

void main(String[] args) throws ParseException {

TimeZone timeZone = TimeZone.getTimeZone("Europe/Moscow");

System.out.println(timeZone);

System.out.println(timeZone.getDisplayName());
System.out.println(timeZone.getID());
System.out.println("Current offset: " + timeZone.getOffset(System.currentTimeMillis())/60/60/1000);
System.out.println("Offset on January 1st 1970: " + timeZone.getOffset(0)/60/60/1000);
}
}

sun.util.calendar.ZoneInfo[id="Europe/Moscow",offset=14400000,dstSavings=0,useDaylight=false,transitions=78,lastRule=null]
Moscow Standard Time
Europe/Moscow
Current offset: 4
Offset on January 1st 1970: 3



Слайд 28Переход на летнее время
public class DaylightSavingsDemo {

public static void

main(String[] args) {

SimpleDateFormat simpleFormat = new SimpleDateFormat("EEEE, dd MMMM yyyy HH:mm:ss zzzz");
TimeZone zone = TimeZone.getTimeZone("Europe/Moscow");
simpleFormat.setTimeZone(zone);

Calendar calendar = new GregorianCalendar();
calendar.setTimeZone(zone);

calendar.set(2010, 2, 28, 2, 0, 0);
calendar.set(Calendar.MILLISECOND,0);

System.out.println(calendar.getTime().getTime());
System.out.println(simpleFormat.format(calendar.getTime()));

calendar.set(2010, 2, 28, 3, 0, 0);
calendar.set(Calendar.MILLISECOND,0);

System.out.println(calendar.getTime().getTime());
}
}


1269730800000
Sunday, 28 March 2010 03:00:00 Moscow Daylight Time
1269730800000



Слайд 29Переход на зимнее время
public class DaylightSavingsFallDemo {

public static void

main(String[] args) {

SimpleDateFormat simpleFormat = new SimpleDateFormat(
"EEEE, dd MMMM yyyy HH:mm:ss zzzz");
TimeZone zone = TimeZone.getTimeZone("Europe/Moscow");
simpleFormat.setTimeZone(zone);

Calendar calendar = new GregorianCalendar();
calendar.setTimeZone(zone);

calendar.set(2010, 9, 31, 1, 0, 0);
calendar.set(Calendar.MILLISECOND, 0);

long time = calendar.getTime().getTime();

for (int i = 0; i < 10; i++) {
System.out.println(simpleFormat.format(time + i*20*60*1000) + " " + (time + i*20*60*1000));
}
}
}


Sunday, 31 October 2010 01:00:00 Moscow Daylight Time 1288472400000
Sunday, 31 October 2010 01:20:00 Moscow Daylight Time 1288473600000
Sunday, 31 October 2010 01:40:00 Moscow Daylight Time 1288474800000
Sunday, 31 October 2010 02:00:00 Moscow Daylight Time 1288476000000
Sunday, 31 October 2010 02:20:00 Moscow Daylight Time 1288477200000
Sunday, 31 October 2010 02:40:00 Moscow Daylight Time 1288478400000
Sunday, 31 October 2010 02:00:00 Moscow Standard Time 1288479600000
Sunday, 31 October 2010 02:20:00 Moscow Standard Time 1288480800000
Sunday, 31 October 2010 02:40:00 Moscow Standard Time 1288482000000
Sunday, 31 October 2010 03:00:00 Moscow Standard Time 1288483200000



Слайд 30

Календари


Слайд 32Класс java.util.Calendar
package java.util;

public abstract class Calendar implements Serializable, Cloneable, Comparable {

protected long time;

public final Date getTime() {
return new Date(getTimeInMillis());
}

public final void setTime(Date date){
setTimeInMillis(date.getTime());
}

public long getTimeInMillis()
public void setTimeInMillis(long millis)
}

time

C

A



Слайд 33Класс java.util.Calendar
package java.util;

public abstract class Calendar implements Serializable, Cloneable, Comparable {

protected int fields[];

public final static int ERA = 0;
public final static int YEAR = 1;
public final static int MONTH = 2;
public final static int WEEK_OF_YEAR = 3;
public final static int WEEK_OF_MONTH = 4;
public final static int DATE = 5;
public final static int DAY_OF_MONTH = 5;
public final static int DAY_OF_YEAR = 6;
public final static int DAY_OF_WEEK = 7;
public final static int DAY_OF_WEEK_IN_MONTH = 8;
public final static int AM_PM = 9;
public final static int HOUR = 10;
public final static int HOUR_OF_DAY = 11;
public final static int MINUTE = 12;
public final static int SECOND = 13;
public final static int MILLISECOND = 14;
public final static int ZONE_OFFSET = 15;

public void set(int field, int value)
public int get(int field)

abstract public void add(int field, int amount)

abstract public void roll(int field, int amount)
}



Слайд 34Класс java.util.GregorianCalendar
package java.util;

public class GregorianCalendar extends Calendar {

public GregorianCalendar() {
this(TimeZone.getDefault(), Locale.getDefault());
}

public GregorianCalendar(TimeZone zone) {
this(zone, Locale.getDefault());
}

public GregorianCalendar(Locale locale) {
this(TimeZone.getDefault(), locale);
}

public GregorianCalendar(TimeZone zone, Locale locale) {
this(zone, locale, false);
setTimeInMillis(System.currentTimeMillis());
}

public GregorianCalendar(int year, int month, int day, int hour, int minute, int second){
this(TimeZone.getDefault(), Locale.getDefault(), false);
set(year, month, day, hour, minute, second);
}
...
}

C



Слайд 35Получение даты и времени
public class CalendarGetDemo {

public static void

main(String[] args) {

Calendar calendar = new GregorianCalendar();

int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); // Jan = 0, not 1
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR);
int weekOfMonth = calendar.get(Calendar.WEEK_OF_MONTH);

System.out.println("year: " + year + ", month: " + month
+ ", dayOfMonth: " + dayOfMonth + ", dayOfWeek: " + dayOfWeek
+ ", weekOfMonth: " + weekOfMonth);

int hour = calendar.get(Calendar.HOUR); // 12 hour clock
int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY); // 24 hour clock
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
int millisecond = calendar.get(Calendar.MILLISECOND);

System.out.println("hour: " + hour + ", hourOfDay: " + hourOfDay
+ ", minute: " + minute + ", second: " + second
+ ", millisecond: " + millisecond);
}
}



Слайд 36Получение даты и времени

year: 2013, month: 0, dayOfMonth: 11, dayOfWeek: 6,

weekOfMonth: 2
hour: 9, hourOfDay: 21, minute: 21, second: 19, millisecond: 609



Слайд 37Задание даты и времени
public class CalendarSetDemo {

public static void

main(String[] args) {

SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

Calendar calendar = new GregorianCalendar();

calendar.set(Calendar.YEAR, 1984);
calendar.set(Calendar.MONTH, 5);
calendar.set(Calendar.DAY_OF_MONTH, 17);

calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 45);
calendar.set(Calendar.SECOND, 58);
calendar.set(Calendar.MILLISECOND, 731);

System.out.println(simpleFormat.format(calendar.getTime()));
}
}


1984-06-17 23:45:58.731



Слайд 38Увеличение даты и времени
public class CalendarAddDemo {

public static void

main(String[] args) {

Calendar calendar = new GregorianCalendar();

calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.DAY_OF_MONTH, 31);
calendar.set(Calendar.YEAR, 2011);

SimpleDateFormat formatter = new SimpleDateFormat("MMM dd, yyyy");
System.out.println("Before adding: " + formatter.format(calendar.getTime()));

calendar.add(Calendar.MONTH, 13);

System.out.println("After adding: " + formatter.format(calendar.getTime()));
}
}


Before adding: Jan 31, 2011
After adding: Feb 29, 2012

2011

2012



Слайд 39“Прокручивание” даты и времени
public class CalendarRollDemo {

public static void

main(String[] args) {

Calendar calendar = new GregorianCalendar();

calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.DAY_OF_MONTH, 31);
calendar.set(Calendar.YEAR, 2011);

SimpleDateFormat formatter = new SimpleDateFormat("MMM dd, yyyy");
System.out.println("Before rolling: " + formatter.format(calendar.getTime()));

calendar.roll(Calendar.MONTH, 13);

System.out.println("After rolling: " + formatter.format(calendar.getTime()));
}
}


Before rolling: Jan 31, 2011
After rolling: Feb 28, 2011

2011

2011



Слайд 40Задание даты и времени
package java.util;

public abstract class Calendar implements Serializable, Cloneable,

Comparable {

public final void set(int year, int month, int date) {
set(YEAR, year);
set(MONTH, month);
set(DATE, date);
}

public final void set(int year, int month, int date, int hourOfDay, int minute) {
set(YEAR, year);
set(MONTH, month);
set(DATE, date);
set(HOUR_OF_DAY, hourOfDay);
set(MINUTE, minute);
}

public final void set(int year, int month, int date, int hourOfDay, int minute, int second) {
set(YEAR, year);
set(MONTH, month);
set(DATE, date);
set(HOUR_OF_DAY, hourOfDay);
set(MINUTE, minute);
set(SECOND, second);
}
}



Слайд 41Задание даты и времени
public class CalendarSetDemo {

public static void

main(String[] args) {

Calendar calendar = new GregorianCalendar();

System.out.println("Current time is: " + calendar.getTime());

calendar.set(2020, 5, 17, 07, 12, 45);

System.out.println("Altered time is: " + calendar.getTime());
}
}


Current time is: Fri Jan 11 22:59:35 GMT+07:00 2013
Altered time is: Wed Jun 17 07:12:45 GMT+07:00 2020



Слайд 42Задание даты и времени
public class CalendarSetPuzzle {

public static

void main(String[] args) {

Calendar calendar1 = new GregorianCalendar();
int year = 2012;
int month = Calendar.MARCH;
int day = 23;
calendar1.set(year, month, day);

int iterationCount = 1000;
boolean isEqual = false;
for (int i = 0; i < iterationCount; i++) {
final Calendar calendar2 = new GregorianCalendar();
calendar2.set(year, month, day);

System.out.println(calendar1.equals(calendar2));
}
}
}



Слайд 43Задание даты и времени
...
true
true
true
true
false
false
false
false
...
true
false


Слайд 44Класс java.util.Calendar
package java.util;

public abstract class Calendar implements Serializable, Cloneable, Comparable {


private boolean lenient = true;

public void setLenient(boolean lenient) {
this.lenient = lenient;
}

public boolean isLenient() {
return lenient;
}
...
}

C

A



Слайд 45Нестрогая проверка изменения полей
public class CalendarLenientDemo {

public static void

main(String[] args) {

Calendar calendar = new GregorianCalendar();
System.out.println("Is calendar lenient? " + calendar.isLenient());

calendar.set(2010, 0, 1);
System.out.println(calendar.getTime());

calendar.set(2010, Calendar.FEBRUARY, 29);
System.out.println(calendar.getTime());
}
}


Is calendar lenient? true
Fri Jan 01 15:19:49 GMT+07:00 2010
Mon Mar 01 15:19:49 GMT+07:00 2010

Jan 01

Mar 01



Слайд 46Строгая проверка изменения полей
public class CalendarNonLenientDemo {

public static void

main(String[] args) {

Calendar calendar = new GregorianCalendar();

calendar.setLenient(false);
System.out.println("Is calendar lenient? " + calendar.isLenient());

calendar.set(2010, 0, 1);
System.out.println(calendar.getTime());

calendar.set(2010, Calendar.FEBRUARY, 29);
System.out.println(calendar.getTime());
}
}


Is calendar lenient? false
Fri Jan 01 15:21:59 GMT+07:00 2010
Exception in thread "main" java.lang.IllegalArgumentException: MONTH: 1 -> 2
at java.util.GregorianCalendar.computeTime(Unknown Source)
at java.util.Calendar.updateTime(Unknown Source)
at java.util.Calendar.getTimeInMillis(Unknown Source)
at java.util.Calendar.getTime(Unknown Source)
at dates.CalendarNonLenientDemo.main(CalendarNonLenientDemo.java:19)



Слайд 47Часовые зоны
package java.util;

public abstract class Calendar implements Serializable, Cloneable, Comparable {


public TimeZone getTimeZone()
public void setTimeZone(TimeZone zone)
...
}

C

A



Слайд 48Использование часовых зон
public class TimeZoneConversionDemo {

public static void main(String[]

args) {

TimeZone timeZoneMOW = TimeZone.getTimeZone("Europe/Moscow");
TimeZone timeZoneLA = TimeZone.getTimeZone("America/Los_Angeles");

Calendar calendar = new GregorianCalendar();

calendar.setTimeZone(timeZoneMOW);

long timeMOW = calendar.getTimeInMillis();
System.out.println("time Moscow = " + timeMOW);
System.out.println("hour = " + calendar.get(Calendar.HOUR_OF_DAY));

calendar.setTimeZone(timeZoneLA);

long timeLA = calendar.getTimeInMillis();
System.out.println("time Los Angeles = " + timeLA);
System.out.println("hour = " + calendar.get(Calendar.HOUR_OF_DAY));
}
}


time Moscow = 1370852587812
hour = 12
time Los Angeles = 1370852587812
hour = 1

1

12



Слайд 49

Форматирование, разбор и валидация даты и времени


Слайд 51Класс java.text.DateFormat
package java.text;

public abstract class DateFormat extends Format{

protected Calendar calendar;

public final String format(Date date)
public Date parse(String source) throws ParseException

public boolean isLenient()
public void setLenient(boolean lenient)

public TimeZone getTimeZone()
public void setTimeZone(TimeZone zone)

public Calendar getCalendar()
public void setCalendar(Calendar newCalendar)

...
}

C

A



Слайд 52Форматирование даты и времени
public class DateFormattingDemo {
public static void

main(String args[]) {

Format formatter;
Calendar calendar = new GregorianCalendar();

calendar.set(Calendar.YEAR,1984);
calendar.set(Calendar.MONTH,5);
calendar.set(Calendar.DAY_OF_MONTH,17);
calendar.set(Calendar.HOUR_OF_DAY,23);
calendar.set(Calendar.MINUTE,45);
calendar.set(Calendar.SECOND,58);
calendar.set(Calendar.MILLISECOND,731);

Date date = calendar.getTime();

formatter = new SimpleDateFormat("MM/dd/yy");
System.out.println(formatter.format(date));

formatter = new SimpleDateFormat("dd/MM/yy");
System.out.println(formatter.format(date));

formatter = new SimpleDateFormat("dd-MMM-yy");
System.out.println(formatter.format(date));

formatter = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
System.out.println(formatter.format(date));

formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
System.out.println(formatter.format(date));

formatter = new SimpleDateFormat("EEEE, dd MMMM yyyy HH:mm:ss zzzz");
System.out.println(formatter.format(date));
}
}



Слайд 53Форматирование даты и времени

06/17/84
17/06/84
17-Jun-84
1984.06.17.23.45.58
Sun, 17 Jun 1984 23:45:58 +0700
Sunday, 17 June

1984 23:45:58 GMT+07:00



Слайд 54Форматирование даты и времени с заданием часовой зоны
public class DateFormattingTzDemo {

public static void main(String args[]) {

SimpleDateFormat formatter;
Calendar calendar = new GregorianCalendar();

calendar.set(Calendar.YEAR,1984);
calendar.set(Calendar.MONTH,5);
calendar.set(Calendar.DAY_OF_MONTH,17);
calendar.set(Calendar.HOUR_OF_DAY,23);
calendar.set(Calendar.MINUTE,45);
calendar.set(Calendar.SECOND,58);
calendar.set(Calendar.MILLISECOND,731);

Date date = calendar.getTime();

formatter = new SimpleDateFormat("EEEE, dd MMMM yyyy HH:mm:ss zzzz");
System.out.println(formatter.format(date));

formatter.setTimeZone(TimeZone.getTimeZone("GMT+0200"));
System.out.println(formatter.format(date));

formatter.setTimeZone(TimeZone.getTimeZone("Europe/Moscow"));
System.out.println(formatter.format(date));

formatter.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
System.out.println(formatter.format(date));
}
}


Sunday, 17 June 1984 23:45:58 Novosibirsk Summer Time
Sunday, 17 June 1984 17:45:58 GMT+02:00
Sunday, 17 June 1984 19:45:58 Moscow Daylight Time
Sunday, 17 June 1984 08:45:58 Pacific Daylight Time



Слайд 55Разбор даты и времени
public class DateParsingDemo {
public static void

main(String args[]) {

DateFormat formatter = new SimpleDateFormat("EEEE, dd MMMM yyyy HH:mm:ss zzzzz");

try {
//On that date Asia/Novosibirsk was GMT+08:00
Date date = formatter.parse("Sunday, 17 June 1984 23:45:58 GMT+03:00");
Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("Asia/Novosibirsk"));

calendar.setTime(date);

int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);

System.out.println("year: " + year + ", month: " + month
+ ", dayOfMonth: " + dayOfMonth + ", hourOfDay: "
+ hourOfDay + ", minute: " + minute + ", second: "
+ second);


} catch (ParseException e) {
e.printStackTrace();
}
}
}


year: 1984, month: 5, dayOfMonth: 18, hourOfDay: 4, minute: 45, second: 58



Слайд 56Разбор даты и времени с заданием часовой зоны
public class DateParsingTzDemo {

public static void main(String args[]) {

DateFormat formatter;

formatter = new SimpleDateFormat("EEEE, dd MMMM yyyy HH:mm:ss");
formatter.setTimeZone(TimeZone.getTimeZone("Europe/Moscow"));

try {
Date date = formatter.parse("Sunday, 17 June 1984 23:45:58");

Calendar calendar = new GregorianCalendar(
TimeZone.getTimeZone("Asia/Novosibirsk"));
calendar.setTime(date);

int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);

System.out.println("year: " + year + ", month: " + month
+ ", dayOfMonth: " + dayOfMonth + ", hourOfDay: "
+ hourOfDay + ", minute: " + minute + ", second: "
+ second);

} catch (ParseException e) {
e.printStackTrace();
}
}
}


year: 1984, month: 5, dayOfMonth: 18, hourOfDay: 4, minute: 45, second: 58



Слайд 57Нестрогая валидация
public class LenientValidationDemo {

public static void main(String[] args)

{

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
System.out.println("Is formatter lenient? " + formatter.isLenient());

String[] strings = { "40/20/2015", "10//10/2015", "50/60/2015", "10.10.2015", "10/10/2015" };

for (String string : strings) {
try {
Date date = formatter.parse(string);
System.out.println(formatter.format(date));

} catch (ParseException e) {
System.out.println("Incorrect date format. " + e.getMessage());
}
}
}
}


Is formatter lenient? true
09/09/2016
Incorrect date format. Unparseable date: "10//10/2015"
19/01/2020
Incorrect date format. Unparseable date: "10.10.2015"
10/10/2015



Слайд 58Строгая валидация
public class NonLenientValidationDemo {

public static void main(String[] args)

{

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
formatter.setLenient(false);
System.out.println("Is formatter lenient? " + formatter.isLenient());

String[] strings = { "40/20/2015", "10//10/2015", "50/60/2015", "10.10.2015", "10/10/2015" };

for (String string : strings) {
try {
Date date = formatter.parse(string);
System.out.println(formatter.format(date));

} catch (ParseException e) {
System.out.println("Incorrect date format. " + e.getMessage());
}
}
}
}


Is formatter lenient? false
Incorrect date format. Unparseable date: "40/20/2015"
Incorrect date format. Unparseable date: "10//10/2015"
Incorrect date format. Unparseable date: "50/60/2015"
Incorrect date format. Unparseable date: "10.10.2015"
10/10/2015



Обратная связь

Если не удалось найти и скачать презентацию, Вы можете заказать его на нашем сайте. Мы постараемся найти нужный Вам материал и отправим по электронной почте. Не стесняйтесь обращаться к нам, если у вас возникли вопросы или пожелания:

Email: Нажмите что бы посмотреть 

Что такое ThePresentation.ru?

Это сайт презентаций, докладов, проектов, шаблонов в формате PowerPoint. Мы помогаем школьникам, студентам, учителям, преподавателям хранить и обмениваться учебными материалами с другими пользователями.


Для правообладателей

Яндекс.Метрика