List of usage examples for java.util Date getYear
@Deprecated public int getYear()
From source file:com.yj.smarthome.activity.control.MainControlActivity.java
/** * ??2014624 17:23./*from ww w.ja v a2 s.com*/ * * @param date * the date * @return the date cn */ public static String getDateCN(Date date) { int y = date.getYear(); int m = date.getMonth() + 1; int d = date.getDate(); int h = date.getHours(); int mt = date.getMinutes(); return (y + 1900) + "" + m + "" + d + " " + h + ":" + mt; }
From source file:org.apache.hadoop.hbase.mob.MobUtils.java
/** * Cleans the expired mob files.//from ww w . ja v a2 s. c o m * Cleans the files whose creation date is older than (current - columnFamily.ttl), and * the minVersions of that column family is 0. * @param fs The current file system. * @param conf The current configuration. * @param tableName The current table name. * @param columnDescriptor The descriptor of the current column family. * @param cacheConfig The cacheConfig that disables the block cache. * @param current The current time. * @throws IOException */ public static void cleanExpiredMobFiles(FileSystem fs, Configuration conf, TableName tableName, HColumnDescriptor columnDescriptor, CacheConfig cacheConfig, long current) throws IOException { long timeToLive = columnDescriptor.getTimeToLive(); if (Integer.MAX_VALUE == timeToLive) { // no need to clean, because the TTL is not set. return; } Date expireDate = new Date(current - timeToLive * 1000); expireDate = new Date(expireDate.getYear(), expireDate.getMonth(), expireDate.getDate()); LOG.info("MOB HFiles older than " + expireDate.toGMTString() + " will be deleted!"); FileStatus[] stats = null; Path mobTableDir = FSUtils.getTableDir(getMobHome(conf), tableName); Path path = getMobFamilyPath(conf, tableName, columnDescriptor.getNameAsString()); try { stats = fs.listStatus(path); } catch (FileNotFoundException e) { LOG.warn("Failed to find the mob file " + path, e); } if (null == stats) { // no file found return; } List<StoreFile> filesToClean = new ArrayList<StoreFile>(); int deletedFileCount = 0; for (FileStatus file : stats) { String fileName = file.getPath().getName(); try { MobFileName mobFileName = null; if (!HFileLink.isHFileLink(file.getPath())) { mobFileName = MobFileName.create(fileName); } else { HFileLink hfileLink = HFileLink.buildFromHFileLinkPattern(conf, file.getPath()); mobFileName = MobFileName.create(hfileLink.getOriginPath().getName()); } Date fileDate = parseDate(mobFileName.getDate()); if (LOG.isDebugEnabled()) { LOG.debug("Checking file " + fileName); } if (fileDate.getTime() < expireDate.getTime()) { if (LOG.isDebugEnabled()) { LOG.debug(fileName + " is an expired file"); } filesToClean.add(new StoreFile(fs, file.getPath(), conf, cacheConfig, BloomType.NONE)); } } catch (Exception e) { LOG.error("Cannot parse the fileName " + fileName, e); } } if (!filesToClean.isEmpty()) { try { removeMobFiles(conf, fs, tableName, mobTableDir, columnDescriptor.getName(), filesToClean); deletedFileCount = filesToClean.size(); } catch (IOException e) { LOG.error("Failed to delete the mob files " + filesToClean, e); } } LOG.info(deletedFileCount + " expired mob files are deleted"); }
From source file:nl.nn.adapterframework.util.FileUtils.java
public static File getRollingFile(String directory, String filenamePrefix, String dateformat, String filenameSuffix, int retentionDays) { final long millisPerDay = 24 * 60 * 60 * 1000; if (directory == null) { return null; }/*w w w . j a v a2 s .c om*/ Date now = new Date(); String filename = filenamePrefix + DateUtils.format(now, dateformat) + filenameSuffix; File result = new File(directory + "/" + filename); if (!result.exists()) { int year = now.getYear(); int month = now.getMonth(); int date = now.getDate(); long thisMorning = new Date(year, month, date).getTime(); long deleteBefore = thisMorning - retentionDays * millisPerDay; WildCardFilter filter = new WildCardFilter(filenamePrefix + "*" + filenameSuffix); File dir = new File(directory); File[] files = dir.listFiles(filter); int count = (files == null ? 0 : files.length); for (int i = 0; i < count; i++) { File file = files[i]; if (file.isDirectory()) { continue; } if (file.lastModified() < deleteBefore) { file.delete(); } } } return result; }
From source file:nz.co.fortytwo.freeboard.server.util.Util.java
/** * Attempt to set the system time using the GPS time * * @param sen//from w ww . java2 s. c o m */ @SuppressWarnings("deprecation") public static void checkTime(RMCSentence sen) { if (timeSet) { return; } try { sen.getPosition(); } catch (DataNotAvailableException e) { return; } try { net.sf.marineapi.nmea.util.Date dayNow = sen.getDate(); //if we need to set the time, we will be WAAYYY out //we only try once, so we dont get lots of native processes spawning if we fail props = getConfig(null); if (props.getProperty(Constants.DEMO).equals("false")) { if (System.getProperty("os.name").startsWith("Windows")) { // includes: Windows 2000, Windows 95, Windows 98, Windows NT, Windows Vista, Windows XP // a Win system will already have the time set. return; } } timeSet = true; Date date = new Date(); net.sf.marineapi.nmea.util.Date gpsDate; //so we need to set the date and time net.sf.marineapi.nmea.util.Time gpsTime = sen.getTime(); gpsDate = sen.getDate(); String hh = pad(2, String.valueOf(gpsTime.getHour())); String mm = pad(2, String.valueOf(gpsTime.getMinutes())); String ss = pad(2, String.valueOf((int) gpsTime.getSeconds())); if (logger.isDebugEnabled()) { logger.debug("Setting current date to " + dayNow + " " + gpsTime); } String cmd = "sudo date --utc " + pad(2, String.valueOf(gpsDate.getMonth())) + pad(2, String.valueOf(gpsDate.getDay())) + hh + mm + gpsDate.getYear() + "." + ss; System.out.println("Setting date " + cmd); // only set the system time if we are not running demo if (props.getProperty(Constants.DEMO).equals("false")) { Runtime.getRuntime().exec(cmd.split(" "));// MMddhhmm[[yy]yy] } if (logger.isDebugEnabled()) { logger.debug("Executed date setting command:" + cmd); } } catch (Exception e) { logger.error(e.getMessage(), e); } }
From source file:com.opendoorlogistics.core.tables.io.PoiIO.java
private static String getTextValue(Cell cell, int treatAsCellType) { if (cell == null) { return null; }//ww w.j a va2s . c o m switch (treatAsCellType) { case Cell.CELL_TYPE_STRING: return cell.getRichStringCellValue().getString(); case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { Date date = cell.getDateCellValue(); if (date != null) { Calendar cal = Calendar.getInstance(); cal.setTime(date); @SuppressWarnings("deprecation") int year = date.getYear(); if (year == -1) { // equivalent to 1899 which is the first data .. assume its a time String s = ODL_TIME_FORMATTER.format(date); return s; } // System.out.println(year); } return cell.getDateCellValue().toString(); } else { String ret = Double.toString(cell.getNumericCellValue()); if (ret.endsWith(".0")) { ret = ret.substring(0, ret.length() - 2); } return ret; } case Cell.CELL_TYPE_BOOLEAN: return cell.getBooleanCellValue() ? "T" : "F"; case Cell.CELL_TYPE_FORMULA: return cell.getCellFormula(); case Cell.CELL_TYPE_BLANK: return null; } return ""; }
From source file:com.autentia.tnt.bean.reports.CommissioningReportBean.java
@Override public ArrayList<SelectItem> getYears() { final ArrayList<SelectItem> reto = new ArrayList<SelectItem>(); final Date date = new Date(); for (int i = date.getYear(); i > date.getYear() - 5; i--) { reto.add(new SelectItem(Integer.toString(1900 + i), Integer.toString(1900 + i))); }// w w w . j av a 2s . com return reto; }
From source file:com.autentia.tnt.validator.DateValidator.java
/** */ public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { log.info("validate - value = " + value); if (value != null) { final Date date = (Date) value; // 0 is the year 1900 if (date.getYear() < 0) { throw new ValidatorException(new FacesMessage("La fecha debe tener el formato dd/mm/aaaa")); }//from w ww .j a va 2s.com } }
From source file:com.taobao.ad.jpa.test.ReportJobRtTest.java
@SuppressWarnings("deprecation") @Test/* ww w . j av a 2 s . c o m*/ public void testGet() { Date d = new Date(); d.setYear(d.getYear() - 1); Assert.assertNotNull(reportJobRtBO.getAverageRt(d, new Date())); System.out.println(reportJobRtBO.getAverageRt(d, new Date())); }
From source file:org.openmrs.module.spike1.web.controller.Spike1ManageController.java
public String getTimestampString(Date date) { return "" + date.getYear() + date.getMonth() + date.getDate() + date.getHours() + (date.getMinutes() - date.getMinutes() % 2); }
From source file:org.shengrui.oa.util.UtilDateTime.java
/** * //w w w. j a v a 2 s .c o m * @param weekNumOff * @return */ @SuppressWarnings("deprecation") public static List<String> getWeekDates(int weekOffset, String pattern) { List<String> list = new ArrayList<String>(); int dateNumOff = weekOffset * 7; SimpleDateFormat sdf = new SimpleDateFormat(pattern); Date now = new Date(); int day = now.getDay(); if (day == 0) day = 7; for (int i = 1; i <= 7; i++) { Date tmpDate = new Date(now.getYear(), now.getMonth(), now.getDate() - day + i + dateNumOff); list.add(sdf.format(tmpDate)); } return list; }