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 String getTimeStamp() {
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
    return sdf.format(cal.getTime());
}

From source file:Util.java

public static int getDayOfMonthFromDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*  w w w. ja v  a  2  s.  c  o  m*/
    return calendar.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static Calendar getMorningCal(int hour, int minute) {
    Calendar c = Calendar.getInstance();
    if (c.get(Calendar.HOUR_OF_DAY) > 3) {
        //next day
        c.set(Calendar.DAY_OF_YEAR, c.get(Calendar.DAY_OF_YEAR) + 1);
    }//from ww w .j  a va  2  s . c  o m
    c.set(Calendar.HOUR_OF_DAY, hour);
    c.set(Calendar.MINUTE, minute);
    c.set(Calendar.SECOND, 0);

    return c;
}

From source file:Main.java

public static int getYear() {
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat yearSdf = new SimpleDateFormat("yyyy");
    String yearString = yearSdf.format(calendar.getTime());
    return Integer.parseInt(yearString);
}

From source file:Main.java

public static Date milisToDate(long miliseconds) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(miliseconds * 1000);
    return c.getTime();
}

From source file:Main.java

public static Long createDate(int year, int month, int day) {
    Calendar calendar = Calendar.getInstance();

    calendar.set(year, month, day);/*from  w w  w. j  ava 2s  .c om*/

    return calendar.getTimeInMillis();

}

From source file:Main.java

public static int getMonth() {
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat monthSdf = new SimpleDateFormat("MM");
    String monthString = monthSdf.format(calendar.getTime());
    return Integer.parseInt(monthString);
}

From source file:Main.java

public static String formatDT() {
    Calendar c = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String formattedDate = df.format(c.getTime());
    System.out.println(formattedDate);
    return formattedDate;
}

From source file:Main.java

public static Calendar getCurrent() {
    return Calendar.getInstance();
}

From source file:Main.java

public static String getNowTime() {
    Calendar nowTime = Calendar.getInstance();
    nowTime.add(Calendar.HOUR_OF_DAY, 8);
    return new SimpleDateFormat("yyyyMMddHHmmssSSS").format(nowTime.getTime());
}