Java Date Now getCurrentTimeForUseInAFileName()

Here you can find the source of getCurrentTimeForUseInAFileName()

Description

get Current Time For Use In A File Name

License

BSD License

Return

The current time, with symbols replaced with underscores, so that we can use it in file names. This is great for logs that have to be tagged with dates.

Declaration

public static String getCurrentTimeForUseInAFileName() 

Method Source Code

//package com.java2s;
/**//from  w ww.  j a  va  2s.  c  om
 * <p>
 * Utilities for manipulating Paths, Files, Directories, etc.
 * </p>
 * <p>
 * <span class="BSDLicense"> This software is distributed under the <a
 * href="http://hci.stanford.edu/research/copyright.txt">BSD License</a>.</span>
 * </p>
 * 
 * @author <a href="http://graphics.stanford.edu/~ronyeh">Ron B Yeh</a> (ronyeh(AT)cs.stanford.edu)
 */

import java.text.DateFormat;

import java.util.Calendar;

public class Main {
    /**
     * @return The current time, with symbols replaced with underscores, so that we can use it in file names.
     *         This is great for logs that have to be tagged with dates.
     */
    public static String getCurrentTimeForUseInAFileName() {
        String time = DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
        // remove symbols that break Windows file names
        time = time.replaceAll(":", "_");
        time = time.replaceAll(",", "");
        return time;
    }
}

Related

  1. getCurrentTimeAsNumber()
  2. getCurrentTimeAsString()
  3. getCurrentTimeForFileName()
  4. getCurrentTimeForLog()
  5. getCurrentTimeForName()
  6. getCurrentTimeInMySqlTime()
  7. getCurrentTimeInMySqlTime()
  8. getCurrentTimeInString(SimpleDateFormat dateFormat)
  9. getCurrentTimeInString(String format)