Here you can find the source of addTimeStampGetPostFix(Date now, TimeUnit unit)
public static String addTimeStampGetPostFix(Date now, TimeUnit unit)
//package com.java2s; /* Copyright (c) 2011 Danish Maritime Authority. * * 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./*from w w w . j a va 2 s. co m*/ */ import java.text.SimpleDateFormat; import java.util.Date; import java.util.concurrent.TimeUnit; public class Main { public static String addTimeStampGetPostFix(Date now, TimeUnit unit) { if (unit == TimeUnit.MINUTES) { // does not handle daylight saving properties // Ogsaa lige et problem hvis den allerede har vaere aabnet // og saa bliver service genstarted return new SimpleDateFormat("yyyy-MM-dd_HH:mm").format(now); } else if (unit == TimeUnit.HOURS) { return new SimpleDateFormat("yyyy-MM-dd_HH").format(now); } else if (unit == TimeUnit.DAYS) { return new SimpleDateFormat("yyyy-MM-dd").format(now); } else { throw new IllegalArgumentException(unit.toString()); } } }