Example usage for java.util Date getMonth

List of usage examples for java.util Date getMonth

Introduction

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

Prototype

@Deprecated
public int getMonth() 

Source Link

Document

Returns a number representing the month that contains or begins with the instant in time represented by this Date object.

Usage

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  .  j  a  v  a2s .com
 */
@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:org.apache.hadoop.hbase.mob.MobUtils.java

/**
 * Cleans the expired mob files./*ww w  .  j a  v  a  2  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:com.yj.smarthome.activity.control.MainControlActivity.java

/**
 * ??2014624 17:23./*w  w  w . j a va  2s . 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 w  w.j av a 2  s.  com*/
    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:com.autentia.tnt.bean.billing.BillExpirationDateBean.java

public void updateExpirationDate() {

    // TODO extract login name to a properties file
    authenticateAs(ConfigurationUtil.getDefault().getAdminUser());

    List<Bill> bills = BillManager.getDefault().getAllEntities(null, new SortCriteria("name"));

    for (Bill b : bills) {

        Date creationDate = b.getCreationDate();

        creationDate.setMonth(creationDate.getMonth() + 1);
        if (!b.getBillPayment().isEmpty()) {
            for (BillPayment bp : b.getBillPayment()) {

                bp.setExpirationDate(creationDate);
            }/*from  w w  w . j  a  v  a 2 s  .c  o  m*/
        } else {
            //creamos el billPayment para el expirationDate
            createBillPayment(b);
            for (BillPayment bp : b.getBillPayment()) {
                bp.setExpirationDate(creationDate);
            }

        }
    }
}

From source file:org.shengrui.oa.util.UtilDateTime.java

/**
 * //w  w  w .j  a va 2 s.co  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:manipulaxmls.Copiar.java

public void copiarXml(String origemNfe) {

    File diretorio;//from  w  w w . j a v a2 s. c o m
    diretorio = new File(origemNfe);
    if (diretorio.exists()) {
        Date modifica = new Date(diretorio.lastModified());
        System.out.println("ultima modificacao: " + modifica);

        File[] lista = diretorio.listFiles();
        File destino = new File(System.getProperty("user.home") + "\\desktop\\contador");
        if (destino.exists()) {

        } else {
            destino.mkdir();
        }
        for (File lista1 : lista) {

            Date dataArq = new Date(lista1.lastModified());
            int anoArq = dataArq.getYear() + 1900;
            int mesArq = dataArq.getMonth() + 1;
            File pastaAno = new File(System.getProperty("user.home") + "\\desktop\\contador" + "\\" + anoArq);
            File pastaMes = new File(
                    System.getProperty("user.home") + "\\desktop\\contador" + "\\" + anoArq + "\\" + mesArq);
            if (pastaAno.exists()) {

            } else {
                pastaAno.mkdir();
            }
            if (pastaMes.exists()) {

            } else {
                pastaMes.mkdir();
            }
            String nomeArq = lista1.getName();
            if (nomeArq.length() == 51) {
                try {

                    destino = pastaMes;
                    FileUtils.copyFileToDirectory(lista1, destino);

                } catch (Exception ex) {
                    System.out.println("ERRO! " + ex);
                }
            }
        }
    } else {
        System.out.println("CAMINHO INEXISTENTE !!!");
        System.out.println("diretorio :" + diretorio);
    }
}

From source file:org.apache.lens.cube.metadata.TimePartition.java

private Date truncate(Date date, UpdatePeriod updatePeriod) {
    if (updatePeriod.equals(UpdatePeriod.WEEKLY)) {
        Date truncDate = DateUtils.truncate(date, Calendar.DAY_OF_MONTH);
        Calendar cal = Calendar.getInstance();
        cal.setTime(truncDate);//from   w ww  . j a  va 2 s .c om
        cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
        return cal.getTime();
    } else if (updatePeriod.equals(UpdatePeriod.QUARTERLY)) {
        Date dt = DateUtils.truncate(date, updatePeriod.calendarField());
        dt.setMonth(dt.getMonth() - dt.getMonth() % 3);
        return dt;
    } else {
        return DateUtils.truncate(date, updatePeriod.calendarField());
    }
}

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;
}