/* * @(#)TestToday.java * * Summary: Display Today's date. * * Copyright: (c) 2009-2010 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.6+ * * Created with: IntelliJ IDEA IDE. * * Version History: * 1.0 2006-03-02 */ package com.mindprod.example; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; /** * Display Today's date. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2006-03-02 * @since 2006-03-02 */ public final class TestToday { // ------------------------------ CONSTANTS ------------------------------ /** * ISO format YYYY-MM-DD, could use other masks. */ private static final SimpleDateFormat SDF = new SimpleDateFormat( "yyyy-MM-dd" ); // --------------------------- main() method --------------------------- /** * 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. System.out.println( dateString ); // display TimeZone String timeZoneName = local.getDisplayName(); System.out.println( timeZoneName ); } }