List of usage examples for org.apache.commons.lang3.time DateFormatUtils format
public static String format(final Calendar calendar, final String pattern)
Formats a calendar into a specific pattern.
From source file:com.eryansky.core.web.upload.FileUploadUtils.java
/** * ?// 2013/01/03/*from w ww . ja va 2 s. co m*/ * * @return */ public static final String datePath() { Date now = new Date(); return DateFormatUtils.format(now, "MM"); }
From source file:cn.mypandora.util.MyDateUtils.java
/** * long???yyyy-MM-dd HH:mm:ss//ww w .ja v a2 s . c om * * @param createTime * @return */ public static String timestamp2Time(String createTime) { long fooTime = Long.parseLong(createTime) * 1000L; return DateFormatUtils.format(fooTime, TIME_FORMAT); }
From source file:cn.mypandora.util.MyDateUtils.java
/** * ?yyyy-MM-dd?/*from w w w .j a v a 2 s. co m*/ * * @param date * @return */ public static String date2StrDate(Date date) { return DateFormatUtils.format(date, DATE_FORMAT); }
From source file:cn.mypandora.util.MyDateUtils.java
/** * ?yyyy-MM-dd HH:mm:ss?//from w w w. jav a2s.c o m * * @param date * @return */ public static String date2StrTime(Date date) { return DateFormatUtils.format(date, TIME_FORMAT); }
From source file:com.streamsets.pipeline.stage.lib.hive.HiveMetastoreUtil.java
/** * Returns the hdfs paths where the avro schema is stored after serializing. * Path is appended with current time so as to have an ordering. * @param rootTableLocation Root Table Location * @return Hdfs Path String.//from w w w. ja va 2 s . co m */ public static String serializeSchemaToHDFS(UserGroupInformation loginUGI, final FileSystem fs, final String rootTableLocation, final String schemaJson) throws StageException { final String folderPath = rootTableLocation + HiveMetastoreUtil.SEP + HiveMetastoreUtil.HDFS_SCHEMA_FOLDER_NAME; final Path schemasFolderPath = new Path(folderPath); final String path = folderPath + SEP + HiveMetastoreUtil.AVRO_SCHEMA + DateFormatUtils.format(new Date(System.currentTimeMillis()), "yyyy-MM-dd--HH_mm_ss"); try { loginUGI.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { if (!fs.exists(schemasFolderPath)) { fs.mkdirs(schemasFolderPath); } Path schemaFilePath = new Path(path); //This will never happen unless two HMS targets are writing, we will error out for this //and let user handle this via error record handling. if (!fs.exists(schemaFilePath)) { try (FSDataOutputStream os = fs.create(schemaFilePath)) { os.writeChars(schemaJson); } } else { LOG.error(Utils.format("Already schema file {} exists in HDFS", path)); throw new IOException("Already schema file exists"); } return null; } }); } catch (Exception e) { LOG.error("Error in Writing Schema to HDFS: " + e.toString(), e); throw new StageException(Errors.HIVE_18, path, e.getMessage()); } return path; }
From source file:edu.virginia.iath.snac.helpers.datastructures.SNACDate.java
/** * Get the formatted date string from a given Calendar object. This uses the output format * set up using the <code>updateOutputFormat</code> method. * //ww w .j a v a 2 s . c om * @param d Calendar object to be parsed to a String. * @return Normalized String of the parsed date. */ private String formattedDate(Calendar d) { return (d == null) ? "null" : DateFormatUtils.format(d.getTime(), outputFormat); }
From source file:com.daphne.es.maintain.editor.web.controller.OnlineEditorController.java
@RequestMapping("compress") public String compress(@RequestParam(value = "parentPath") String parentPath, @RequestParam(value = "paths") String[] paths, RedirectAttributes redirectAttributes) throws IOException { String rootPath = sc.getRealPath(ROOT_DIR); parentPath = URLDecoder.decode(parentPath, Constants.ENCODING); Date now = new Date(); String pattern = "yyyyMMddHHmmss"; String compressPath = parentPath + File.separator + "[]" + DateFormatUtils.format(now, pattern) + "-" + System.nanoTime() + ".zip"; for (int i = 0, l = paths.length; i < l; i++) { String path = paths[i];//from w ww . j a v a 2 s . c o m path = URLDecoder.decode(path, Constants.ENCODING); paths[i] = rootPath + File.separator + path; } try { CompressUtils.zip(rootPath + File.separator + compressPath, paths); String msg = "?<a href='%s/%s?path=%s' target='_blank' class='btn btn-primary'></a>???"; redirectAttributes.addFlashAttribute(Constants.MESSAGE, String.format(msg, sc.getContextPath(), viewName("download"), URLEncoder.encode(compressPath, Constants.ENCODING))); } catch (Exception e) { redirectAttributes.addFlashAttribute(Constants.ERROR, e.getMessage()); } redirectAttributes.addAttribute("path", URLEncoder.encode(parentPath, Constants.ENCODING)); return redirectToUrl(viewName("list")); }
From source file:me.j360.idgen.impl.test.TableIdGenServiceJdbcTest.java
/** * [Flow #-13] Positive Case : when generate id, apply generation strategy * (TimestampStrategy)./*from ww w . ja v a 2 s. com*/ * * @throws Exception * fail to test */ @Test public void testGetStringIdWithKeyTable() throws Exception { IdGenService idGenerator1 = (IdGenService) applicationContext.getBean("Ids-TestWithoutTableKey"); // 1. Initialize the counter in the database. initializeNextLongId("MOVIE", 1); initializeNextLongId("GENRE", 1); // 2. generate id with stragety (pattern : // 'yyyyMMdd', separator : '', cipers : 5, fillChar : // '0') String currentTime = DateFormatUtils.format(new Date(), "yyyyMMdd"); for (int i = 0; i < 5; i++) { assertEquals(currentTime + "0000" + (i + 1), idGenerator1.getNextStringId("MOVIE")); } for (int i = 0; i < 5; i++) { assertEquals(currentTime + "0000" + (i + 1), idGenerator1.getNextStringId("GENRE")); } IdGenService idGenerator2 = (IdGenService) applicationContext .getBean("Ids-TestWithPatternedTimestampStrategy"); currentTime = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH"); // 3. generate id with stragety (pattern : // 'yyyyMMddHHmmssSSS', separator : '-', cipers : 5, fillChar : // '*') for (int i = 5; i < 9; i++) { assertEquals(currentTime + "-****" + (i + 1), idGenerator2.getNextStringId("MOVIE")); } for (int i = 5; i < 9; i++) { assertEquals(currentTime + "-****" + (i + 1), idGenerator2.getNextStringId("GENRE")); } }
From source file:me.j360.idgen.impl.test.TableIdGenServiceJdbcTest.java
/** * [Flow #-14] Positive Case : when generate id, apply generation strategy * (TimestampStrategy). And id management table doesn't have initial counter * for 'MOVIE_NEW'/*from w ww . ja v a 2s . c o m*/ * * @throws Exception * fail to test */ @Test public void testGetStringIdWithoutInitCounter() throws Exception { IdGenService idGenerator1 = (IdGenService) applicationContext.getBean("Ids-TestWithoutTableKey"); // 1. generate id with stragety (pattern : // 'yyyyMMdd', separator : '', cipers : 5, fillChar : // '0') String currentTime = DateFormatUtils.format(new Date(), "yyyyMMdd"); for (int i = 0; i < 5; i++) { assertEquals(currentTime + "0000" + (i + 1), idGenerator1.getNextStringId("MOVIE_NEW")); } }
From source file:com.norconex.commons.lang.file.FileUtil.java
/** * Creates (if not already existing) a series of directories reflecting * a date, up to the day unit, under a given parent directory. For example, * a date of 2000-12-31 will create the following directory structure: * <code>/*from w ww . j ava 2s . c om*/ * /<parentDir>/2000/12/31/ * </code> * @param parentDir the parent directory where to create date directories * @param date the date to create directories from * @return the directory representing the full path created * @throws IOException if the parent directory is not valid */ public static File createDateDirs(File parentDir, Date date) throws IOException { if (parentDir == null) { throw new IOException("Parent directory cannot be null."); } if (date == null) { throw new IOException("Date cannot be null."); } if (parentDir.exists() && !parentDir.isDirectory()) { throw new IOException("Parent directory \"" + parentDir + "\" already exists and is not a directory."); } File dateDir = new File(parentDir.getAbsolutePath() + "/" + DateFormatUtils.format(date, "yyyy/MM/dd")); FileUtils.forceMkdir(dateDir); return dateDir; }