/* * [TestToday.java] * * Summary: Display Today's date. * * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2006-03-02 */ package com.mindprod.example; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; import static java.lang.System.*; /** * Display Today's date. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2006-03-02 * @since 2006-03-02 */ public final class TestToday { /** * ISO format YYYY-MM-DD, could use other masks. */ private static final SimpleDateFormat SDF = new SimpleDateFormat( "yyyy-MM-dd" ); /** * Display current date e.g. 2006-01-22 * * @param args not used */ public static void main( String[] args ) { // we must pick a TimeZone since at any given instant, // part of the world is on Sunday and part on is on Monday, // part on the 22 and part on the 23. // if wanted UTC // TimeZone utc = TimeZone.getTimeZone( "UTC" ); // if wanted Eastern standard elapsedTime // TimeZone est = TimeZone.getTimeZone( "America/New_York" ); // if wanted user's local TimeZone TimeZone local = TimeZone.getDefault(); SDF.setTimeZone( local ); // new Date() gets current date/elapsedTime String dateString = SDF.format( new Date() ); // display the date YYYY-MM-DD, adjusted for timezon and daylight savings. out.println( dateString ); // display TimeZone String timeZoneName = local.getDisplayName(); out.println( timeZoneName ); } }