Example usage for java.util Date getTime

List of usage examples for java.util Date getTime

Introduction

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

Prototype

public long getTime() 

Source Link

Document

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.

Usage

From source file:DateUtil.java

public static long dateToLong(Date date) {
    return date.getTime();
}

From source file:Main.java

public static String getTimeStamp(String time) {
    SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.CHINA);
    Date date;
    String times = null;//from   w  w  w .  j a  v  a 2  s.  c  o  m
    try {
        date = sdr.parse(time);
        long l = date.getTime();
        String stf = String.valueOf(l);
        times = stf.substring(0, 10);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return times;
}

From source file:BufferDiff.java

static int time(OutputStream os) throws IOException {
    Date then = new Date();
    for (int i = 0; i < 500000; i++) {
        os.write(1);/*  www.  j a  v  a2 s. co  m*/
    }
    os.close();
    return (int) ((new Date()).getTime() - then.getTime());
}

From source file:Main.java

/**
 * Coverts the specified date/time value to specific milliseconds.
 * /*  w w w  . j  av a2 s . co m*/
 * @param str to convert into specific date/time.
 * @return converted milliseconds value.
 */
public static long getDateTimeinMilliSeconds(String str) {
    long milliseconds = 0;
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    //formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date startdate = null;
    try {
        startdate = formatter.parse(str);
        milliseconds = startdate.getTime();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return milliseconds;
}

From source file:Main.java

public static boolean judgeTime2Time(String time1, String time2) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    try {//w w w.j a v  a2  s . com
        Date date1 = sdf.parse(time1);
        Date date2 = sdf.parse(time2);
        long l1 = date1.getTime() / 1000;
        long l2 = date2.getTime() / 1000;
        if (l2 - l1 > 0) {
            return true;
        } else {
            return false;
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return false;
}

From source file:Main.java

public static void writeDate(Parcel parcel, Date date) {
    if (date == null) {
        parcel.writeLong(Long.MIN_VALUE);
    } else {//www. j  a v a  2s .com
        parcel.writeLong(date.getTime());
    }
}

From source file:Main.java

public static long getBetweenDiff(String startTime, String endTime, String format) {
    long diff = 0;
    SimpleDateFormat ft = new SimpleDateFormat(format);
    try {/*from w w w  .  j a  va  2 s .c  o  m*/
        Date startDate = ft.parse(startTime);
        Date endDate = ft.parse(endTime);
        diff = startDate.getTime() - endDate.getTime();
        diff = diff / 1000;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return diff;
}

From source file:com.b5m.you.common.util.DateUtils.java

/**
 * ?/*from   ww w  . ja v a2 s.co  m*/
 * 
 * @param deadline
 *            ,?yyyyMMddHHmmss
 * @return
 */
public static String getRemainingTime(String endDate) {
    String rtn = "";
    if (StringUtils.isBlank(endDate))
        return rtn;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");// ComConstants.SDF_YYYYMMDDHHMMSS;//???
    try {
        Date deadline = sdf.parse(endDate);
        long remaining = deadline.getTime() - System.currentTimeMillis();
        // long remaining=lngDeadline-System.currentTimeMillis();
        if (remaining > 0) {
            int ms = (int) (remaining % 1000);
            remaining /= 1000;
            int sc = (int) (remaining % 60);
            remaining /= 60;
            int mn = (int) (remaining % 60);
            remaining /= 60;
            int hr = (int) (remaining % 24);
            long dy = (int) remaining / 24;
            rtn = dy + "" + hr + "?" + mn + "";// + sc + "";
        } else {
            rtn = "";
        }
    } catch (ParseException e) {

    }
    return rtn;
}

From source file:Main.java

public static long getTwoDay(String sj1, String sj2) {
    SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
    long day = 0;
    try {//  w  w w.  j a  v  a 2 s  .c  om
        java.util.Date date = myFormatter.parse(sj1);
        java.util.Date mydate = myFormatter.parse(sj2);
        day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
    } catch (Exception e) {
        return 0;
    }
    return day;
}

From source file:Main.java

public static Date firstTimeOfMonth(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(date.getTime());

    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.DAY_OF_MONTH, 1);

    Date dateBegin = new Date();
    dateBegin.setTime(calendar.getTimeInMillis());
    return dateBegin;
}