Example usage for java.util Calendar set

List of usage examples for java.util Calendar set

Introduction

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

Prototype

public final void set(int year, int month, int date, int hourOfDay, int minute, int second) 

Source Link

Document

Sets the values for the fields YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE, and SECOND.

Usage

From source file:Main.java

public static Timestamp getCurrentDate() {

    Calendar c = Calendar.getInstance();
    c.set(c.get(1), c.get(2), c.get(5), 0, 0, 0);
    Timestamp t = new Timestamp(c.getTime().getTime());
    t.setNanos(0);/*from  ww  w.  j a  v  a2 s. c o  m*/
    return t;
}

From source file:Main.java

public static Calendar dateToCalendar(String date) {
    String[] theDate = date.split(" ");
    Calendar calDate = Calendar.getInstance();
    calDate.set(Integer.parseInt(theDate[0]), Integer.parseInt(theDate[1]) - 1, Integer.parseInt(theDate[2]),
            Integer.parseInt(theDate[3]), Integer.parseInt(theDate[4]), Integer.parseInt(theDate[5]));
    return calDate;
}

From source file:Main.java

/**
 * My son's birthday! This serves no purpose OTHER than a shoutout to him, love ya kid.
 * @return Date object/*from w ww. j a v  a  2s  .com*/
 */
public static Date getLiamsBirthday() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(2016, 7, 4, 12, 29, 30);
    Date date = calendar.getTime();
    return date;
}

From source file:Main.java

/**
 * For when I need a quick date in the year 1985. Don't judge me, I get lazy and don't
 * want to type my birthday multiple times.
 * @return Date object/*  w  w w . j av  a2 s  . c  o m*/
 */
public static Date get1985() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(1985, 10, 8, 11, 11, 11);
    Date date = calendar.getTime();
    return date;
}

From source file:Main.java

public static Date getTime(int year, int month, int day) {
    Calendar date = Calendar.getInstance();
    date.set(year, month, day, 0, 0, 0);
    date.set(Calendar.MILLISECOND, 0);
    return date.getTime();
}

From source file:Main.java

public static Date getTime(int year, int month, int day, int hour, int minute) {
    Calendar date = Calendar.getInstance();
    date.set(year, month, day, hour, minute, 0);
    date.set(Calendar.MILLISECOND, 0);
    return date.getTime();
}

From source file:Main.java

public static int getNumberOfWeeksInMonth(int year, int month) {
    Calendar calendar = Calendar.getInstance(Locale.FRANCE);
    calendar.set(year, month, 1, 0, 0, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar.getActualMaximum(Calendar.WEEK_OF_MONTH);
}

From source file:Main.java

public static Date getDate(int year, int month, int day, int hour, int min, int sec) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(year, (month - 1), day, hour, min, sec);
    return calendar.getTime();
}

From source file:Main.java

public static Date makeDate(int year, int month, int day) {
    Calendar cal = Calendar.getInstance();
    cal.clear();/*www  .  j  av a  2  s.  c  o  m*/
    cal.set(year, month - 1, day, 0, 0, 0);
    return cal.getTime();
}

From source file:Main.java

public static long getLocalToUtcDelta() {
    Calendar local = Calendar.getInstance();
    local.clear();/*  w  w  w  .  j  a  v  a  2 s  .co m*/
    local.set(1970, Calendar.JANUARY, 1, 0, 0, 0);
    return local.getTimeInMillis();
}