Java tutorial
//package com.java2s; /* * Copyright 2012 AT&T * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Calendar; import java.util.Date; public class Main { /** * Gets the default ARO trace folder name in the HH:MM:SS:DD:MM:YY format. * * @return The default ARO trace folder name. */ public static String getDefaultTraceFolderName() { final Date systemDate = new Date(); final Calendar now = Calendar.getInstance(); final int currenthours = systemDate.getHours(); final int currentminutes = systemDate.getMinutes(); final int currentseconds = systemDate.getSeconds(); final int currentdate = now.get(Calendar.DATE); // java calendar int currentmonth = now.get(Calendar.MONTH); // As Jan is defined as 0 in currentmonth = currentmonth + 1; if (currentmonth >= 13) // As Jan is defined as 0 in java calendar currentmonth = 1; String currentMonth = Integer.toString(currentmonth); String currentDate = Integer.toString(currentdate); String currentHours = Integer.toString(currenthours); String currentMinutes = Integer.toString(currentminutes); String currentSeconds = Integer.toString(currentseconds - 1); if (currentmonth < 10) { currentMonth = ""; currentMonth = "0" + currentmonth; } if (currentdate < 10) { currentDate = ""; currentDate = "0" + currentdate; } if (currenthours < 10) { currentHours = ""; currentHours = "0" + currenthours; } if (currentminutes < 10) { currentMinutes = ""; currentMinutes = "0" + currentminutes; } if (currentseconds < 10) { currentSeconds = ""; currentSeconds = "0" + currentseconds; } final String folderName = now.get(Calendar.YEAR) + "-" + currentMonth + "-" + currentDate + "-" + currentHours + "-" + currentMinutes + "-" + currentSeconds; return folderName; } }