Example usage for java.util Calendar getTimeInMillis

List of usage examples for java.util Calendar getTimeInMillis

Introduction

In this page you can find the example usage for java.util Calendar getTimeInMillis.

Prototype

public long getTimeInMillis() 

Source Link

Document

Returns this Calendar's time value in milliseconds.

Usage

From source file:Main.java

public static Long getYesterday() {
    Calendar yesterday = Calendar.getInstance();
    yesterday.setTimeZone(TimeZone.getDefault());

    yesterday.set(Calendar.SECOND, 0);
    yesterday.set(Calendar.MINUTE, 0);
    yesterday.set(Calendar.HOUR_OF_DAY, 1);
    yesterday.set(Calendar.MILLISECOND, 0);

    int day = yesterday.get(Calendar.DAY_OF_YEAR);

    yesterday.set(Calendar.DAY_OF_YEAR, day - 1);

    return yesterday.getTimeInMillis();
}

From source file:com.augmentum.common.util.DateUtil.java

public static Date convertTimeZones(Calendar fromCal, String tzId) {
    Date date = null;/*from   w  w  w  .  ja v  a  2  s. c  o  m*/

    if ((fromCal != null) && StringUtils.isNotBlank(tzId)) {
        Calendar tzCal = new GregorianCalendar(TimeZone.getTimeZone(tzId));
        tzCal.setTimeInMillis(fromCal.getTimeInMillis());
        date = tzCal.getTime();
    }

    return date;
}

From source file:Main.java

/**
 * Add date time over one year.//  w w  w.  j a  v  a2 s. c o m
 *
 * @param listing     the listing
 * @param currentTime the current time
 * @param isPast      true/false if past time
 */
private static void addDateTimeOverOneYear(final List<Long> listing, final long currentTime,
        final boolean isPast) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    calendar.add(Calendar.MONTH, isPast ? -4 : 4);
    calendar.add(Calendar.YEAR, isPast ? -1 : 1);
    listing.add(calendar.getTimeInMillis());
}

From source file:emily.util.YTUtil.java

/**
 * Time until the next google api reset happens (Midnight PT), or 9am GMT
 *
 * @return formatted string, eg. "10 minutes form now"
 *//*from ww  w  . j  a va  2 s .  c  om*/
public static String nextApiResetTime() {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DAY_OF_MONTH, 0);
    c.set(Calendar.HOUR_OF_DAY, 9);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return TimeUtil.getRelativeTime(
            (System.currentTimeMillis()
                    + (c.getTimeInMillis() - System.currentTimeMillis()) % TimeUnit.DAYS.toMillis(1)) / 1000L,
            false);
}

From source file:com.chess.genesis.net.GenesisNotifier.java

public static void ScheduleWakeup(final Context context) {
    final Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MINUTE, Pref.getInt(context, R.array.pf_notifierPolling));
    final long start = cal.getTimeInMillis();
    final long interval = start - System.currentTimeMillis();

    final Intent intent = new Intent(context, GenesisAlarm.class);
    final PendingIntent pintent = PendingIntent.getBroadcast(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.setInexactRepeating(AlarmManager.RTC, start, interval, pintent);
}

From source file:com.weavers.duqhan.util.FileUploader.java

public static CloudineryImageDto uploadImage(String imgUrl) {
    CloudineryImageDto imageBean = new CloudineryImageDto();
    imageBean.setUrl("failure");
    String timeInMili = String.valueOf(new Date().getTime());
    Map params = Cloudinary.asMap("public_id", timeInMili);
    Calendar calendar = Calendar.getInstance();
    List<Transformation> eager = Arrays.asList(new Transformation().width(512).height(512).crop("thumb"));
    Cloudinary cloudinary = new Cloudinary(ObjectUtils.asMap("cloud_name", CLOUD_NAME, "api_key", API_KEY,
            "tags", "product", "timestamp", calendar.getTimeInMillis(), "api_secret", API_SECRET,
            // "upload_preset", "gpucdhrn",
            //  "transformation", incoming,
            "eager", eager));

    Map uploadResult;/*w w  w .  j  a v  a  2 s.  co  m*/
    String url = null;
    try {
        //            cloudinary.url().type("fetch").imageTag("http://upload.wikimedia.org/wikipedia/commons/0/0c/Scarlett_Johansson_Csars_2014.jpg");
        uploadResult = cloudinary.uploader().upload(imgUrl, ObjectUtils.emptyMap());
        String publicId = (String) uploadResult.get("public_id");
        url = (String) uploadResult.get("url");
        System.out.println("url == " + url);
        String signature = (String) uploadResult.get("signature");
        String format = (String) uploadResult.get("format");
        String secureUrl = (String) uploadResult.get("secure_url");
        Integer version = (Integer) uploadResult.get("version");

        //<editor-fold defaultstate="collapsed" desc="Image Bean">
        imageBean.setFormat(format);
        imageBean.setPublicId(publicId);
        imageBean.setSecureUrl(secureUrl);
        imageBean.setSignature(signature);
        imageBean.setVersion(Long.valueOf(version));
        imageBean.setUrl(url);
        //</editor-fold>

    } catch (Exception ex) {
        java.util.logging.Logger.getLogger(FileUploader.class.getName()).log(Level.SEVERE, null, ex);
        //            System.out.println("eeeeeeeeeee"+ex.getLocalizedMessage());
        imageBean.setUrl("failure");
    }
    return imageBean;
}

From source file:com.weavers.duqhan.util.FileUploader.java

public static CloudineryImageDto uploadImage(MultipartFile file) {
    CloudineryImageDto imageBean = new CloudineryImageDto();
    imageBean.setUrl("failure");
    String timeInMili = String.valueOf(new Date().getTime());
    Map params = Cloudinary.asMap("public_id", timeInMili);
    Calendar calendar = Calendar.getInstance();
    List<Transformation> eager = Arrays.asList(new Transformation().width(512).height(512).crop("thumb"));
    Cloudinary cloudinary = new Cloudinary(ObjectUtils.asMap("cloud_name", CLOUD_NAME, "api_key", API_KEY,
            "tags", "product", "timestamp", calendar.getTimeInMillis(), "api_secret", API_SECRET,
            // "upload_preset", "gpucdhrn",
            //  "transformation", incoming,
            "eager", eager));

    Map uploadResult;//from  w w w . ja  v  a 2 s.com
    String url = null;
    try {
        //            cloudinary.url().type("fetch").imageTag("http://upload.wikimedia.org/wikipedia/commons/0/0c/Scarlett_Johansson_Csars_2014.jpg");
        byte[] file1 = file.getBytes();
        uploadResult = cloudinary.uploader().upload(file1, params);
        //            cloudinary.url().transformation(new Transformation().width(512).height(512).crop("fill")).imageTag(params);
        String publicId = (String) uploadResult.get("public_id");
        url = (String) uploadResult.get("url");
        String signature = (String) uploadResult.get("signature");
        String format = (String) uploadResult.get("format");
        String secureUrl = (String) uploadResult.get("secure_url");
        Integer version = (Integer) uploadResult.get("version");

        //<editor-fold defaultstate="collapsed" desc="Image Bean">
        imageBean.setFormat(format);
        imageBean.setPublicId(publicId);
        imageBean.setSecureUrl(secureUrl);
        imageBean.setSignature(signature);
        imageBean.setVersion(Long.valueOf(version));
        imageBean.setUrl(url);
        //</editor-fold>

    } catch (Exception ex) {
        java.util.logging.Logger.getLogger(FileUploader.class.getName()).log(Level.SEVERE, null, ex);
        //            System.out.println("eeeeeeeeeee"+ex.getLocalizedMessage());
        imageBean.setUrl("failure");
    }
    return imageBean;
}

From source file:com.kongwu.insweb.utils.DateUtils.java

public static int daysBetween(Date smdate, Date bdate) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    smdate = sdf.parse(sdf.format(smdate));
    bdate = sdf.parse(sdf.format(bdate));
    Calendar cal = Calendar.getInstance();
    cal.setTime(smdate);//from   w  w w .  j  a va 2s.  co m
    long time1 = cal.getTimeInMillis();
    cal.setTime(bdate);
    long time2 = cal.getTimeInMillis();
    long between_days = (time2 - time1) / (1000 * 3600 * 24);
    return Integer.parseInt(String.valueOf(between_days));
}

From source file:com.orange.oidc.tim.service.TokensKeys.java

static String makeExpires64(String durationExpires) {
    if (durationExpires != null) {
        try {//from   w w w . j  ava2  s  . co  m
            int duration = Integer.parseInt(durationExpires);
            if (duration > 1) {
                Calendar cal = Calendar.getInstance();
                cal.add(Calendar.SECOND, duration);
                byte[] bytes = ByteBuffer.allocate(8).putLong(cal.getTimeInMillis()).array();

                return KryptoUtils.encodeB64(bytes);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return "";
}

From source file:Main.java

/**
 * Decode a 16-bit encoded DOS date/time into a java date/time.
 * /* w w  w.j  a  v a  2  s  .c  o m*/
 * @param dosDate
 * @param dosTime
 * @return long
 */
public static long decodeDateTime(int dosDate, int dosTime) {
    final Calendar cal = Calendar.getInstance();

    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.SECOND, (dosTime & 0x1f) * 2);
    cal.set(Calendar.MINUTE, (dosTime >> 5) & 0x3f);
    cal.set(Calendar.HOUR_OF_DAY, dosTime >> 11);

    cal.set(Calendar.DATE, dosDate & 0x1f);
    cal.set(Calendar.MONTH, ((dosDate >> 5) & 0x0f) - 1);
    cal.set(Calendar.YEAR, 1980 + (dosDate >> 9));

    return cal.getTimeInMillis();
}