List of usage examples for java.util Calendar getInstance
public static Calendar getInstance()
From source file:Main.java
public static boolean isDayOrNight() { Calendar calendar = Calendar.getInstance(); int hour = calendar.get(Calendar.HOUR_OF_DAY); if (hour >= 0 && hour < 18) return true; else//w w w. j a v a 2 s . c o m return false; }
From source file:Main.java
public static int getWeekOfYear(long timeInMillis) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(timeInMillis);//from www .j av a 2 s. c o m return cal.get(Calendar.WEEK_OF_YEAR); }
From source file:Main.java
public static int getCurrentSeason() { Calendar c = Calendar.getInstance(); int month = c.get(Calendar.MONTH); if (month >= 0 && month < 3) { return 1; } else if (month > 3 && month < 6) { return 2; } else if (month > 6 && month < 9) { return 3; }//w w w . j a va 2 s. c o m return 4; }
From source file:Main.java
public static Date getDate() { Calendar c = Calendar.getInstance(); Date d = c.getTime(); return d; }
From source file:Main.java
public static String getDateYYYYMM(int offset) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH, offset); return calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.MONTH); }
From source file:Main.java
public static int getYear() { Calendar c = Calendar.getInstance(); c.setTime(new Date()); int year = c.get(Calendar.YEAR); return year;/* w w w . j a va 2 s .c o m*/ }
From source file:Main.java
public static int getHour() { Calendar c = Calendar.getInstance(); c.setTime(new Date()); int hour = c.get(Calendar.HOUR_OF_DAY); return hour;/* w ww. j a va 2 s. c o m*/ }
From source file:Main.java
public static boolean isNationalDay() { Calendar calendar = Calendar.getInstance(); int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DAY_OF_MONTH); if (month == 10 && day <= 7) { return true; }/* w ww .j a v a 2s. c o m*/ return false; }
From source file:Main.java
private static Date getTimeNow() { Calendar c = Calendar.getInstance(); return c.getTime(); }
From source file:Main.java
public static String timeAgo(Long timestamp) { Long now = Calendar.getInstance().getTime().getTime(); Long seconds = (now - timestamp) / 1000; String time = " ("; Long day = seconds / 86400;/*from w ww . ja v a 2 s .c o m*/ Long hours = (seconds % 86400) / 3600; //Long mins = (seconds % 3600) / 60; //Long sec = seconds % 60; time += day + "d " + hours + "h " + " ago)"; return time; }