Example usage for java.util Date setTime

List of usage examples for java.util Date setTime

Introduction

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

Prototype

public void setTime(long time) 

Source Link

Document

Sets this Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.

Usage

From source file:Main.java

public static String getNextHour(String format, int h) {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    Date date = new Date();
    date.setTime(date.getTime() + h * 60 * 60 * 1000);
    return sdf.format(date);

}

From source file:Main.java

/**
 * //from  ww  w  .ja v  a 2 s .  c o  m
 * @param milliseconds
 * @return
 */
public static Date GetDateByTimeMills(long milliseconds) {
    Date date = new Date();
    date.setTime(milliseconds);

    return date;
}

From source file:Main.java

public static String formatDate(long milliseconds) {
    Date time = getDate();
    time.setTime(milliseconds);
    return formatter0.format(time);
}

From source file:Main.java

public static long toDate(long millis) {
    Date currentTime = new Date();
    currentTime.setTime(millis);
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
    return Long.parseLong(formatter.format(currentTime));
}

From source file:Main.java

public static java.util.Date getDate(long time) {
    java.util.Date date = new java.util.Date();
    date.setTime(time);
    return date;/*w  w  w.  j  a  va  2s. co  m*/
}

From source file:Main.java

public static Date firstTimeOfWeek(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_WEEK, Calendar.SUNDAY);

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

From source file:Main.java

public static java.util.Date toDate(Calendar c) {
    if (c == null)
        return null;
    java.util.Date date = new java.util.Date();
    date.setTime(c.getTimeInMillis());
    return date;/*from w  ww .  j  a  va  2s. c  om*/
}

From source file:Main.java

public static String IntToDate(long pTime) {
    Date vD = new Date();
    if (pTime != 0)
        vD.setTime(pTime);
    SimpleDateFormat vDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return vDF.format(vD);
    //       return (String) DateFormat.format("yyyy-MM-dd hh:mm:ss", vTime);
}

From source file:Main.java

public static Date firstTimeOfDate(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);
    Date dateBegin = new Date();
    dateBegin.setTime(calendar.getTimeInMillis());
    return dateBegin;
}

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