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:Main.java

/**
 * Parsing the TimeZone of time in milliseconds.
 *
 * @param gmtTime GRM Time, Format such as: {@value #FORMAT_HTTP_DATA}.
 * @return The number of milliseconds from 1970.1.1.
 * @throws ParseException if an error occurs during parsing.
 */// w  w  w . java2s . c om
public static long parseGMTToMillis(String gmtTime) throws ParseException {
    SimpleDateFormat formatter = new SimpleDateFormat(FORMAT_HTTP_DATA, Locale.US);
    formatter.setTimeZone(GMT_TIME_ZONE);
    Date date = formatter.parse(gmtTime);
    return date.getTime();
}

From source file:Main.java

public static Timestamp toTimestamp(LocalDate localDate) {
    Date date = Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
    Timestamp timeStamp = new Timestamp(date.getTime());
    return timeStamp;
}

From source file:Main.java

public static String getNextDay(String nowdate, String delay) {
    try {/*from ww w .java  2 s.  c  om*/
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String mdate = "";
        Date d = strToDate(nowdate);
        long myTime = (d.getTime() / 1000) + Integer.parseInt(delay) * 24 * 60 * 60;
        d.setTime(myTime * 1000);
        mdate = format.format(d);
        return mdate;
    } catch (Exception e) {
        return "";
    }
}

From source file:Main.java

public static String getYearMonthDay2() {

    java.util.Date date1 = new java.util.Date();
    java.sql.Date date3 = new java.sql.Date(date1.getTime());
    return date3.toString();
}

From source file:Main.java

public static long getTempTime(String time) {
    try {//from  w  w w.  j  a  v  a2  s  .  c om
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleDateFormat.parse(time);
        long tempTime = date.getTime();
        return tempTime;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return 0;
}

From source file:Main.java

public static long getUnixTime(Date date) {
    if (date == null) {
        return 0;
    }// w  w  w.ja  v  a 2s  . c  o m

    return date.getTime() / 1000L;
}

From source file:Main.java

/**
 * Create an unix timestamp of a date object
 * @param date/*from   ww w. j  a v a2 s.c  o  m*/
 * @return seconds since 1970-1-1
 */
public static Long toUnixtimeTimestamp(Date date) {
    if (date == null) {
        return null;
    }
    return date.getTime() / 1000L;
}

From source file:MainClass.java

public static java.sql.Timestamp getTimestamp() {
    java.util.Date today = new java.util.Date();
    return new java.sql.Timestamp(today.getTime());
}

From source file:Main.java

public static long getTime(@Nullable Date date) {
    long time = -1;
    if (date != null) {
        time = date.getTime();
    }/*w w  w. j  ava  2  s .c om*/
    return time;
}

From source file:Main.java

public static String ymdhm2Timestamp(String dateString) throws ParseException {
    String timeStamp = null;// w  ww.jav  a2 s . c o m
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH/mm");
    Date d;
    try {
        d = sdf.parse(dateString);
        long l = d.getTime() / 1000;
        timeStamp = String.valueOf(l);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return timeStamp;
}