Example usage for java.util Calendar getInstance

List of usage examples for java.util Calendar getInstance

Introduction

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

Prototype

public static Calendar getInstance() 

Source Link

Document

Gets a calendar using the default time zone and locale.

Usage

From source file:Main.java

public static int getNowMonthOfYear() {
    return Calendar.getInstance().get(Calendar.MONTH);
}

From source file:Main.java

public static int getYearFromDate(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);/*  w ww  . jav  a2s  . c  o m*/
    return c.get(Calendar.YEAR);
}

From source file:Main.java

public static int getYear() {
    Calendar now = Calendar.getInstance();
    return now.get(Calendar.YEAR);
}

From source file:Main.java

public static String getDate() {
    Calendar c = Calendar.getInstance();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String currentTime = dateFormat.format(c.getTime());
    return currentTime;
}

From source file:Main.java

public static int getMonth(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*from   w w w .  j  a v  a 2  s . co  m*/
    return calendar.get(Calendar.MONTH);
}

From source file:Main.java

public static int getDaysByYearMonth(int year, int month) {

    Calendar a = Calendar.getInstance();
    a.set(Calendar.YEAR, year);/*from  w w w  .  j a va  2s  . co m*/
    a.set(Calendar.MONTH, month - 1);
    a.set(Calendar.DATE, 1);
    a.roll(Calendar.DATE, -1);
    return a.get(Calendar.DATE);
}

From source file:Main.java

public static int getMonthFromDate(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);/*from   w ww. j  a va 2s  .  c o m*/
    return c.get(Calendar.MONTH);
}

From source file:Main.java

public static Integer GetDayOfMonth(Date d) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);
    return cal.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static int getMonth() {
    Calendar now = Calendar.getInstance();
    return now.get(Calendar.MONTH) + 1;
}

From source file:Main.java

public static String getTodayDateString() {
    Calendar now = Calendar.getInstance();
    int year = now.get(Calendar.YEAR);
    int month = now.get(Calendar.MONTH) + 1;
    int day = now.get(Calendar.DAY_OF_MONTH);

    String monthStr = String.valueOf(month);
    String dayStr = String.valueOf(day);

    if (month < 10) {
        monthStr = "0" + dayStr;
    }//from   w ww  .j  a va  2  s  .  co  m
    if (day < 10) {
        dayStr = "0" + dayStr;
    }

    String nowDate = year + "-" + monthStr + "-" + dayStr;
    return nowDate;
}