Mega Code Archive

 
Categories / Java / Data Type
 

A method to get the current date as an array of components 0 = year, 1 = month, 2 = day

/*  * This file is part of the AusStage Utilities Package  *  * The AusStage Utilities Package is free software: you can redistribute  * it and/or modify it under the terms of the GNU General Public License   * as published by the Free Software Foundation, either version 3 of the  * License, or (at your option) any later version.  *  * The AusStage Utilities Package is distributed in the hope that it will   * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty   * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  * GNU General Public License for more details.  *  * You should have received a copy of the GNU General Public License  * along with the AusStage Utilities Package.    * If not, see <http://www.gnu.org/licenses/>. */ //package au.edu.ausstage.utils; // import additional libraries import java.util.GregorianCalendar; import java.util.Calendar; import java.text.DateFormat; /**  * A class of methods useful when processing dates in AusStage Services  */ public class DateUtils {   /**    * A method to get the current date as an array of components    * 0 = year, 1 = month, 2 = day    *    * @return an array of strings representing the current date    */   public static String[] getCurrentDateAsArray() {        GregorianCalendar calendar = new GregorianCalendar();     String[] fields = new String[3];          fields[0] = Integer.toString(calendar.get(Calendar.YEAR));     fields[1] = String.format("%02d", calendar.get(Calendar.MONTH) + 1);     fields[2] = String.format("%02d", calendar.get(Calendar.DAY_OF_MONTH));          return fields;     }    }