📜 ⬆️ ⬇️

Summer time

At work they were asked: what will the next program type if it is launched on March 1, 2009 at exactly noon in New York? (Instead of New York, you can run the program in Moscow - the answer will change, but not its essence).
Nothing complicated or new in this, but, in my opinion, this is one of those little things that spoil life very much.

Language does not matter, we were presented with a version in Java:
import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  1. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  2. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  3. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  4. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  5. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  6. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  7. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  8. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  9. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  10. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  11. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  12. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  13. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  14. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  15. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  16. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
  17. import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .
import java.text.SimpleDateFormat; import java.util.Date; public class Question { private static final long SECONDS_PER_DAY = 24 * 60 * 60; private static final SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" ); public static void main( String [] args) { for ( int i = 0; i < 30; i++) { System. out .println( "The time is: " + sdf.format( new Date())); try { // wait until tomorrow Thread.sleep(1000 * SECONDS_PER_DAY); } catch (InterruptedException e) { } } } } * This source code was highlighted with Source Code Highlighter .

Assume that the program runs from start to finish, and that sleep is not interrupted.

This begs the answer that the program will print 30 lines The time is: 12:00:00 .

In fact, starting from a certain date, which just depends on the place of execution, the output of the program will become The time is: 1 3 :00:00 . It will happen because of the transition to summer time (March 8 in the United States, March 29 in Russia).
')
It turns out that at least twice a year in a day is not 24 * 60 * 60 seconds.

I hope this will save some time. :-)

Source: https://habr.com/ru/post/53172/


All Articles