Example usage for java.util Date getDate

List of usage examples for java.util Date getDate

Introduction

In this page you can find the example usage for java.util Date getDate.

Prototype

@Deprecated
public int getDate() 

Source Link

Document

Returns the day of the month represented by this Date object.

Usage

From source file:com.krawler.esp.handlers.basecampHandler.java

public static long getDiff(Date dt1, Date dt2) {
    Date dt3 = new Date(dt1.getYear(), dt1.getMonth(), dt1.getDate());
    Date dt4 = new Date(dt2.getYear(), dt2.getMonth(), dt2.getDate());

    long diff = (dt3.getTime() - dt4.getTime()) / (1000 * 60 * 60 * 24);
    return diff;//from  www .j  a v  a  2  s .  com

}

From source file:org.rifidi.emulator.reader.llrp.report.LLRPReportController.java

/**
 * Gets the UTC Time./*w  ww .  ja va 2 s  .  com*/
 * 
 * @param dateString
 * @param timeString
 * @return time in milliseconds
 */
@SuppressWarnings("deprecation")
private static long getUTCTimeInMillis(String dateString, String timeString) {

    /*
     * TODO: baindaid solution until radio saves and returns java date and
     * time objects
     */
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
    SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");

    Date date, time = null;
    try {
        date = dateFormat.parse(dateString);
        time = timeFormat.parse(timeString);
    } catch (ParseException e) {
        logger.error("There was a problem converting the date or time string into a Date object");
        date = new Date();
        time = new Date();
    }

    GregorianCalendar gc = new GregorianCalendar(date.getYear(), date.getMonth(), date.getDate(),
            time.getHours(), time.getMinutes(), time.getSeconds());

    return gc.getTimeInMillis();
}

From source file:org.apache.hadoop.hbase.mob.MobUtils.java

/**
 * Cleans the expired mob files.//from   ww w  . ja va  2s .  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:com.yj.smarthome.activity.control.MainControlActivity.java

/**
 * ??2014624 17:23.//from   w  w  w.j a v  a 2  s.co  m
 * 
 * @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: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  ww.  jav a  2s  . c o m*/
    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: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

/**
 * /*ww w  .  j a v a 2s  .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;

}

From source file:org.openmrs.module.pmtct.PregnancyDateManager.java

@SuppressWarnings("deprecation")
public String getNumberOfWeeks(String dateOfPeriod) throws Exception {
    Date lastDateOfPeriod = Context.getDateFormat().parse(dateOfPeriod);

    GregorianCalendar last_DateOfPeriod = new GregorianCalendar(lastDateOfPeriod.getYear(),
            lastDateOfPeriod.getMonth(), lastDateOfPeriod.getDate());
    last_DateOfPeriod.setLenient(false);

    Date da = new Date();

    //      slog.info("xxxxxxxxxxxxxxx"+(new GregorianCalendar(da.getYear()+1900,da.getMonth(),da.getDate())).getTime());

    //1 week=604800000 milliseconds = (1000ms*60s*60min*24h*7days)

    return "**********************"
            + (((new GregorianCalendar(da.getYear(), da.getMonth(), da.getDate())).getTimeInMillis())
                    - (last_DateOfPeriod.getTimeInMillis())) / 604800000;
}

From source file:org.openmrs.module.pmtct.PregnancyDateManager.java

@SuppressWarnings("deprecation")
public String getDPA(String dateOfPeriod) throws Exception {
    Date lastDateOfPeriod = Context.getDateFormat().parse(dateOfPeriod);

    GregorianCalendar last_DateOfPeriod = new GregorianCalendar(lastDateOfPeriod.getYear() + 1900,
            lastDateOfPeriod.getMonth(), lastDateOfPeriod.getDate());

    last_DateOfPeriod.setLenient(false);
    last_DateOfPeriod.add(Calendar.DAY_OF_YEAR, PMTCTConstants.DELAY_IN_DAYS_OF_PREGNANCY);

    return Context.getDateFormat().format(last_DateOfPeriod.getTime());
}

From source file:com.wonders.stpt.metroIndicator.service.impl.MetroProductionServiceImpl.java

@SuppressWarnings("deprecation")
public List<ProductionVo> findSevenDaysProduction(String endDate, String line) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    List<ProductionVo> voList = new ArrayList<ProductionVo>();

    if (endDate == null || "".equals(endDate)) {
        endDate = sdf.format(new Date());
    }/*from  w w  w .  ja  v a  2s.  c o  m*/
    try {

        //?
        List<MetroProduction> dataList = metroProductionDao.findProductionWithData(endDate, line);
        if (dataList != null && dataList.size() != 0) {
            endDate = dataList.get(0).getIndicatorDate();
        }
        Date start = sdf.parse(endDate); //   
        start.setDate(start.getDate() - 5);
        List<MetroProduction> productList = metroProductionDao.findSevenDaysProduction(sdf.format(start),
                endDate, line);
        if (productList != null && productList.size() != 0) {
            for (int i = 0; i < productList.size(); i++) {
                ProductionVo vo = new ProductionVo(productList.get(i));
                voList.add(vo);
            }
        }
        return voList;
    } catch (ParseException e) {
        return null;
    }
}