List of usage examples for java.util GregorianCalendar GregorianCalendar
public GregorianCalendar()
GregorianCalendar
using the current time in the default time zone with the default Locale.Category#FORMAT FORMAT locale. From source file:Main.java
public static java.util.Date getDateStart(java.util.Date d) { Calendar c = new GregorianCalendar(); c.clear();/* w w w .ja v a 2 s. c om*/ Calendar co = new GregorianCalendar(); co.setTime(d); c.set(Calendar.DAY_OF_MONTH, co.get(Calendar.DAY_OF_MONTH)); c.set(Calendar.MONTH, co.get(Calendar.MONTH)); c.set(Calendar.YEAR, co.get(Calendar.YEAR)); // c.add(Calendar.DAY_OF_MONTH,1); // c.add(Calendar.MILLISECOND,-1); return c.getTime(); }
From source file:Main.java
public static int getWeekOfYear(String year, String month, String day) { Calendar cal = new GregorianCalendar(); cal.clear();//from w ww . j av a 2 s . co m cal.set(new Integer(year).intValue(), new Integer(month).intValue() - 1, new Integer(day).intValue()); return cal.get(Calendar.WEEK_OF_YEAR); }
From source file:Main.java
public static String getCreateTime() { String createtime = null;//from w w w . j a v a 2s. com Calendar calendar = new GregorianCalendar(); createtime = Long.toString(calendar.getTimeInMillis()); return createtime; }
From source file:Main.java
public static int toH(long time) { Date dat = new Date(time); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dat);//w w w . java 2s .c om java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("HH"); String sb = format.format(gc.getTime()); int i = Integer.parseInt(sb); return i; }
From source file:Main.java
public static String toHM(long time) { Date dat = new Date(time); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dat);//from www . j a v a 2s. c o m java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("HH:mm"); String sb = format.format(gc.getTime()); return sb; }
From source file:Main.java
public static int toM(long time) { Date dat = new Date(time); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dat);//from ww w .j av a2s . co m java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("mm"); String sb = format.format(gc.getTime()); int i = Integer.parseInt(sb); return i; }
From source file:Main.java
public static int toTimeM(long time) { Date dat = new Date(time); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dat);//from w w w . jav a 2 s. co m java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("mm"); String sb = format.format(gc.getTime()); int i = Integer.parseInt(sb); return i; }
From source file:Main.java
public static String formatDateDiff(long date) { Calendar c = new GregorianCalendar(); c.setTimeInMillis(date);/*from ww w .ja va2 s . c o m*/ Calendar now = new GregorianCalendar(); return formatDateDiff(now, c); }
From source file:Main.java
@SuppressWarnings("deprecation") public static String changeDateAsMonth(String date, int imonth) { GregorianCalendar calendar = new GregorianCalendar(); if (date.length() == 8) { calendar.set(Integer.parseInt(date.substring(0, 4)), Integer.parseInt(date.substring(4, 6)) - 1, Integer.parseInt(date.substring(6, 8))); } else if (date.length() == 10) { calendar.set(Integer.parseInt(date.substring(0, 4)), Integer.parseInt(date.substring(5, 7)) - 1, Integer.parseInt(date.substring(8, 10))); }/*from w ww .j av a2 s . com*/ calendar.add(GregorianCalendar.MONTH, imonth); String sDate[] = calendar.getTime().toLocaleString().split(" "); return sDate[0]; }
From source file:Main.java
public static String weekDay(String year, String month, String day) { String strWeekday = ""; try {//from w w w .j a v a2 s .c om GregorianCalendar cal = new GregorianCalendar(); cal.setLenient(false); cal.clear(); cal.set(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day)); strWeekday = String.valueOf(cal.get(Calendar.DAY_OF_WEEK) - 1); } catch (IllegalArgumentException e) { strWeekday = ""; } return strWeekday; }