Time is not on my side.

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

Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Problem of the Day Problem of the Day next Using a Calculator.
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 –
Getting Started with Java Recitation – 1/23/2009 CS 180 Department of Computer Science, Purdue University.
TELLING TIME LINKS Identifies days, weeks, and months on a calendar.
Date processing and conversion Please use speaker notes for additional information!
Nic Shulver, Date and Time in JSP Surely it must be easy? Many calendars exist. The year 2013 (“Gregorian” or “Western”) is also:
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 –
ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming javascript dates.
Homework Sec. 1.3 # 16, 29, 40, 48, I like to get rid of the fractions by multiplying both sides by the LCD. Then I get all the variables on one.
Programming. Exam Validation 1-10 Technical words such as Method of validation Do not use “Something”.
Announcements There is a Quiz today. There were problems with grading assignment 2, but they should be worked out today The web page for correcting the.
IMS 3253: Dates and Times 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Date and Time Data Turning Strings into.
IGCSE ECONOMICS COSTS To explain the difference between the long run and the short run. To identify and calculate the various different costs To explain.
Chapter 3 Math Operations. Objectives Use the assignment and arithmetic operators. Use operators in output statements. Explain the problem with division.
Homework Notes from Sean
Working with Date ISYS 350.
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
The Science & Invention Fair
©GoGrade Name: ____________________________________________________ Date: _________________________ Problem: You.
AKA – Input/output tables
Do you know all these facts?
The Science & Invention Fair
Java String and Date ISYS 350.
Lesson 05: Iterations Class Chat: Attendance: Participation
SQL – Dates and Times.
Testing & Testing Tools
The Science & Invention Fair
Servlet Date Operations
Java Date ISYS 350.
CSC 253 Lecture 8.
CSC 253 Lecture 8.
Working with DateTime Data
Use proper case (ie Caps for the beginnings of words)
Learning Outcomes –Lesson 4
Objective The student will be able to:
Part B – Structured Exception Handling
Tonga Institute of Higher Education
Equations: Multi-Step Examples ..
TechEd /11/ :44 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered.
Christmas Opening Hours
Java Date ISYS 350.
CMSC201 Computer Science I for Majors Lecture 25 – Final Exam Review
Alejandra lopez & Hinn wit yi (snow)
Tech·Ed North America /17/2019 6:01 PM
Solving Equations.
February 7th, 2019 What will YOU do?.
Introduction to Programming with Python
Student Voice Survey
Financial Market Theory
Bug Report Part 3.
NEED SOME DIRECTION WITH APPLYING TO THE NURSING MAJOR?
Select Import Text File from the Data, Get External Data menu on the toolbar. Browse to the correct folder and select the required file.
Java Date ISYS 350.
Lecture 14: Testing Testing used to verify object behavior through designed test suites Can test Classes – “unit” testing Object interactions – “integration”
design OO words Debug Variables Data types
Skip a page for the toc Lesson 16 Solving one step equations
If your time was: Your wpm are: Your wpm are: 1: 3: 1: 3: 1: 3: 3: 1:
Absolute = Absolute.
CSE 206 Course Review.
Do you know all these facts?
Procedures.
Draw a line 2/3 the way across DO THIS TO THE BACK ALSO
Murach's JavaScript and jQuery (3rd Ed.)
Java Date ISYS 350.
Complete the family of four
Exceptions Review Checked Vs. Unchecked Exceptions
Tuesday January 31st, 2017 Learning Target;
Working with dates and times
Presentation transcript:

Time is not on my side

Guess the Output – Part 1 try it: https://ideone.com/f9Qj4C SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dateFormat.setTimeZone(TimeZone.getTimeZone("America/Chicago")); String dateString1 = "2017-05-25 10:50:00"; // May 26th 2017, 10:50:00 AM String dateString2 = "2017-05-25 10:50:01"; // May 26th 2017, 10:50:01 AM Date date1 = dateFormat.parse(dateString1); // Parse string to date Date date2 = dateFormat.parse(dateString2); // Parse string to date long milliSecondDifference = date2.getTime() - date1.getTime(); // Subtract dates long secondsDifference = milliSecondDifference / 1000; // Milliseconds to Seconds System.out.println(secondsDifference); Correct output is 1 second Try it yourself try it: https://ideone.com/f9Qj4C

Guess the Output – Part 2 try it: https://ideone.com/KZ9DXg SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")); String dateString1 = "1900-12-31 23:54:16"; // December 31st 1900 11:54:16 PM String dateString2 = "1900-12-31 23:54:17"; // December 31st 1900 11:54:17 PM Date date1 = dateFormat.parse(dateString1); // Parse string to date Date date2 = dateFormat.parse(dateString2); // Parse string to date long milliSecondDifference = date2.getTime() - date1.getTime(); // Subtract dates long secondsDifference = milliSecondDifference / 1000; // Milliseconds to Seconds System.out.println(secondsDifference); Expected output is 1 second Correct output is 344 second Try it yourself try it: https://ideone.com/KZ9DXg

Why? https://www.youtube.com/embed/-5wpm-gesOY?start=18&end=462&version=3 Backup link: https://www.youtube.com/watch?v=-5wpm-gesOY Start 18s End 7:36

Stack Overflow - Question https://stackoverflow.com/questions/6841333/why-is-subtracting-these-two-times-in-1927-giving-a-strange-result/6841479#6841479

Stack Overflow - Answer https://stackoverflow.com/questions/6841333/why-is-subtracting-these-two-times-in-1927-giving-a-strange-result/6841479#6841479

2012 Microsoft Azure Bug Occurred at 4:00 PM on February 28th, 2012 (PST) Code calculated a certificate expiration date, 1 year from the current issuing date. February 29th, 2013 is not a valid date, caused a cascading failure Caused service disruptions to Azure for 12 hours SYSTEMTIME st; // declare a SYSTEMTIME variable GetSystemTime(&st); // set it to the current date and time st.wYear++; // increment it by one year February 28th, 2012 (PST) is 00:00 February 29th (UST) https://azure.microsoft.com/en-us/blog/summary-of-windows-azure-service-disruption-on-feb-29th-2012/

isLeapYear(int year) { return year % 4 == 0 } Fixing the bug isLeapYear(int year) { return year % 4 == 0 } What about the year 2100 (not a leap year) They skip centuries

Moral of the Story Don’t reinvent the wheel Know your edge cases DateTime.AddYears will take into account leap years Know your edge cases Test your edge cases