Java Path Create makePathFromDate()

Here you can find the source of makePathFromDate()

Description

Make a string that defines a path from the root of the storage service's documents tree to a specific document directory.

License

Open Source License

Return

the path string.

Declaration

public static String makePathFromDate() 

Method Source Code


//package com.java2s;
/*---------------------------------------------------------------
*  Copyright 2005 by the Radiological Society of North America
*
*  This source software is released under the terms of the
*  RSNA Public License (http://mirc.rsna.org/rsnapubliclicense)
*----------------------------------------------------------------*/

import java.io.File;

import java.util.Calendar;

public class Main {
    /**/*from www  .  ja va2  s .  c om*/
     * Make a string that defines a path from the root of the
     * storage service's documents tree to a specific document
     * directory. The path has the form: YYYY/MM/DDhhmmsssss
     * where the values come from the current time and the slash
     * character is actually either a slash or backslash, depending
     * on the platform.
     * @return the path string.
     */
    public static String makePathFromDate() {
        Calendar now = Calendar.getInstance();
        return intToString(now.get(Calendar.YEAR), 4) + File.separator + intToString(now.get(Calendar.MONTH) + 1, 2)
                + File.separator + intToString(now.get(Calendar.DAY_OF_MONTH), 2)
                + intToString(now.get(Calendar.HOUR_OF_DAY), 2) + intToString(now.get(Calendar.MINUTE), 2)
                + intToString(now.get(Calendar.SECOND), 2) + intToString(now.get(Calendar.MILLISECOND), 3);
    }

    /**
     * Convert a positive int to a String with at least n digits,
     * padding with leading zeroes.
     * @param theValue the int to be converted.
     * @param nDigits the number of digits to return.
     * @return the converted value.
     */
    public static String intToString(int theValue, int nDigits) {
        String s = Integer.toString(theValue);
        int k = nDigits - s.length();
        for (int i = 0; i < k; i++)
            s = "0" + s;
        return s;
    }
}

Related

  1. makePath(String... elements)
  2. makePath(String[] strings)
  3. makePathAbsolute(String path)
  4. makePathASafeFileName(String filePath)
  5. makePathFile(String javaConnectorSourcePath, String packageName, String className)
  6. makePathFromStrings(List files)
  7. makePathName(String directoryName, String fileName)
  8. makePathRelativeTo(String path, final File basedir)
  9. makePaths(File path)