List of usage examples for java.util Calendar get
public int get(int field)
From source file:Main.java
public static int getCurrentMonthDay() { return Calendar.getInstance().get(Calendar.DAY_OF_MONTH); }
From source file:Main.java
public static Calendar getRandomApodDate() { Calendar newCalendar = Calendar.getInstance(); Calendar today = Calendar.getInstance(); int currentYear = today.get(Calendar.YEAR); int currentMonth = today.get(Calendar.MONTH); int currentDay = today.get(Calendar.DATE); int firstApodYear = 1995; int firstApodMonth = 5; int firstApodDay = 20; Random rnd = new Random(); int newYear = rnd.nextInt(currentYear - firstApodYear + 1) + firstApodYear; int minMonth = 0; int maxMonth = 11; if (newYear == firstApodYear) minMonth = firstApodMonth;/* w ww . j a v a2s .c o m*/ if (newYear == currentYear) maxMonth = currentMonth; int newMonth = rnd.nextInt(maxMonth - minMonth + 1) + minMonth; newCalendar.set(newYear, newMonth, 1); int minDay = 1; int maxDay = newCalendar.getActualMaximum(Calendar.DAY_OF_MONTH); if (newYear == firstApodYear && newMonth == firstApodMonth) minDay = firstApodDay; if (newYear == currentYear && newMonth == currentMonth) maxDay = currentDay; int newDay = rnd.nextInt(maxDay - minDay + 1) + minDay; newCalendar.set(newYear, newMonth, newDay); return newCalendar; }
From source file:Main.java
public static int getCurrentMonth() { return Calendar.getInstance().get(Calendar.MONTH); }
From source file:Main.java
/** * Encode a java date/time into a 16-bit encoded DOS date * //from w w w. j a v a 2 s . c o m * @param javaDateTime * @return long */ public static int encodeDate(long javaDateTime) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(javaDateTime); return 512 * (cal.get(Calendar.YEAR) - 1980) + 32 * (cal.get(Calendar.MONTH) + 1) + cal.get(Calendar.DATE); }
From source file:Main.java
/** * Encode a java date/time into a 16-bit encoded DOS time * /*from www . j av a2 s .com*/ * @param javaDateTime * @return long */ public static int encodeTime(long javaDateTime) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(javaDateTime); return 2048 * cal.get(Calendar.HOUR_OF_DAY) + 32 * cal.get(Calendar.MINUTE) + cal.get(Calendar.SECOND) / 2; }
From source file:Main.java
public static String dateToString(String dateString) { Calendar date = Calendar.getInstance(); date.setTimeInMillis((long) Integer.parseInt(dateString) * 1000); return date.get(Calendar.DAY_OF_MONTH) + "/" + String.format("%02d", date.get(Calendar.MONTH) + 1); }
From source file:Main.java
public static String getNowTime(int i) { SimpleDateFormat dft = new SimpleDateFormat("yyyyMMdd"); Date beginDate = new Date(); Calendar date = Calendar.getInstance(); date.setTime(beginDate);// w ww . j a v a 2 s . co m date.set(Calendar.DATE, date.get(Calendar.DATE) - i); Date endDate = null; try { endDate = dft.parse(dft.format(date.getTime())); String format = dft.format(endDate); return format; } catch (ParseException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static int dayForWeek(String pTime) throws Exception { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = Calendar.getInstance(); c.setTime(format.parse(pTime));//www . j ava 2 s . c o m int dayForWeek = 0; return c.get(Calendar.DAY_OF_WEEK); }
From source file:Main.java
public static String getTime() { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis()); return cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND); }
From source file:Main.java
/** * Converts input time from Java to DOS format * @param time//from w w w.ja v a2s . com * @return time in DOS format */ public static long javaToDosTime(long time) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(time); int year = cal.get(Calendar.YEAR); if (year < 1980) { return (1 << 21) | (1 << 16); } return (year - 1980) << 25 | (cal.get(Calendar.MONTH) + 1) << 21 | cal.get(Calendar.DATE) << 16 | cal.get(Calendar.HOUR_OF_DAY) << 11 | cal.get(Calendar.MINUTE) << 5 | cal.get(Calendar.SECOND) >> 1; }