Java Date Format Pattern getSimpleDataFormattedFile(File file)

Here you can find the source of getSimpleDataFormattedFile(File file)

Description

This method will be called for create a backup file.

License

Open Source License

Parameter

Parameter Description
file target file

Return

File backup file whose filename consists of "hogehoge.yyyyMMddHHmmss.ext" or "hogehoge.yyyyMMddHHmmss".

Declaration

public static File getSimpleDataFormattedFile(File file) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2010 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from  w w w . jav  a 2s.c  o m
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.io.*;

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    /**
     * This method will be called for create a backup file.
     * 
     * @param file target file
     * @return File backup file whose filename consists of "hogehoge.yyyyMMddHHmmss.ext" or 
     *    "hogehoge.yyyyMMddHHmmss".
     */
    public static File getSimpleDataFormattedFile(File file) {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); //$NON-NLS-1$
        String date = df.format(new Date());
        String filename = file.getName();
        int index = filename.lastIndexOf("."); //$NON-NLS-1$
        if (index != -1)
            filename = filename.substring(0, index) + "." + date + "." + filename.substring(index + 1); //$NON-NLS-1$ //$NON-NLS-2$
        else
            filename = filename + "." + date; //$NON-NLS-1$
        File dest = new File(file.getParentFile(), filename);
        return dest;
    }
}

Related

  1. getMMDDYYHHMM()
  2. getMMDDYYYY(final Date date, final String separator)
  3. getMomentFormatter()
  4. getPooledSDF(String format)
  5. getSdf(String formatPattern)
  6. getSortedTimetampFormat()
  7. getStringAcordFormat()
  8. getSupportedFormats()
  9. isEqual(String d1, String d2, String format)