Java Utililty Methods Date Now

List of utility methods to do Date Now

Description

The list of methods to do Date Now are organized into topic(s).

Method

StringgetCurrentUTCString()
Get current date in yyyy-dddThh:mm:ss.sss format (GMT)
NumberFormat i3 = NumberFormat.getInstance();
NumberFormat i2 = NumberFormat.getInstance();
i3.setMinimumIntegerDigits(3);
i2.setMinimumIntegerDigits(2);
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
String date = cal.get(Calendar.YEAR) + "-" + i3.format(cal.get(Calendar.DAY_OF_YEAR)) + "T"
        + i2.format(cal.get(Calendar.HOUR_OF_DAY)) + ":" + i2.format(cal.get(Calendar.MINUTE)) + ":"
        + i2.format(cal.get(Calendar.SECOND)) + "." + i3.format(cal.get(Calendar.MILLISECOND));
...
DategetCurrentUTCTime()
get Current UTC Time
try {
    return stringDateToDate(getCurrentUTCTimeAsString());
} catch (ParseException e) {
    e.printStackTrace();
return null;
StringgetCurrentUTCTimeAsString()
get Current UTC Time As String
final SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
final String utcTime = sdf.format(new Date());
return utcTime;
StringgetCurrentWeekDay(Date date, int day)
get Current Week Day
Calendar calendar = getCalendarFromDate(date);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setMinimalDaysInFirstWeek(DAYS_OF_A_WEEK);
int week = calendar.get(Calendar.WEEK_OF_YEAR);
int year = calendar.get(Calendar.YEAR);
return formatDate(getDateOfYearWeek(year, week, day));
ListgetCurrentWeekDays()
get Current Week Days
List<String> currentweek = new ArrayList<String>();
for (int kindex = 1; kindex <= 7; kindex++) {
    Calendar c = Calendar.getInstance();
    int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
    if (day_of_week == 0)
        day_of_week = 7;
    c.add(Calendar.DATE, -day_of_week + kindex);
    String currentday = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
...
StringgetCurrentWeekFirst()
get Current Week First
StringBuffer str = new StringBuffer();
java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");
Calendar c = new GregorianCalendar();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.setTime(new Date());
c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); 
str.append(df.format(c.getTime()));
str.append(" 00:00:00");
...
StringgetCurrentYear()
get Current Year
if (sCurrentYear == null) {
    sCurrentYear = new SimpleDateFormat("yyyy").format(Calendar.getInstance().getTime());
return sCurrentYear;
DategetCurrentYearBegDate(Date date)
get Current Year Beg Date
try {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    String strDate = format.format(date);
    String[] split = strDate.split("-");
    String year = split[0];
    String beginDate = year + "-" + "01" + "-" + "01";
    Date parse = format.parse(beginDate);
    return parse;
...
StringgetCurrentYMDDate()
get Current YMD Date
Calendar cal = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
CurrentTime = formatter.format(cal.getTime());
return CurrentTime;
DategetCurrentZeroTime()
get Current Zero Time
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();