congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
GregorianCalendar.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
java.util.GregorianCalendar
constructor

Best Java code snippets using java.util.GregorianCalendar.<init> (Showing top 20 results out of 14,724)

Refine searchRefine arrow

  • Calendar.getTime
  • Calendar.get
  • Calendar.setTime
  • Calendar.set
  • PrintStream.println
  • SimpleDateFormat.<init>
  • Calendar.add
origin: stackoverflow.com

 GregorianCalendar c = new GregorianCalendar();
c.setTime(yourDate);
XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
origin: stackoverflow.com

 // today    
Calendar date = new GregorianCalendar();
// reset hour, minutes, seconds and millis
date.set(Calendar.HOUR_OF_DAY, 0);
date.set(Calendar.MINUTE, 0);
date.set(Calendar.SECOND, 0);
date.set(Calendar.MILLISECOND, 0);

// next day
date.add(Calendar.DAY_OF_MONTH, 1);
origin: stackoverflow.com

 Calendar startCalendar = new GregorianCalendar();
startCalendar.setTime(startDate);
Calendar endCalendar = new GregorianCalendar();
endCalendar.setTime(endDate);

int diffYear = endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR);
int diffMonth = diffYear * 12 + endCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH);
origin: stackoverflow.com

 Calendar cal = new GregorianCalendar();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
dateFormat.setTimeZone(cal.getTimeZone());
System.out.println(dateFormat.format(cal.getTime()));
origin: stackoverflow.com

 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

// replace with your start date string
Date d = df.parse("2008-04-16 00:05:05"); 
Calendar gc = new GregorianCalendar();
gc.setTime(d);
gc.add(Calendar.HOUR, 2);
Date d2 = gc.getTime();
origin: stackoverflow.com

Calendar c = new GregorianCalendar();
c.set(Calendar.HOUR_OF_DAY, 12);
c.set(Calendar.MINUTE, 58);
c.set(Calendar.SECOND, 15);
Date d = c.getTime();
Calendar c = new GregorianCalendar();
c.setTime(d);
if (c.get(Calendar.SECOND) >= 30)
  c.add(Calendar.MINUTE, 1);
c.set(Calendar.SECOND, 0);
return c.getTime();
Calendar c = new GregorianCalendar();
c.setTime(d);
if (c.get(Calendar.MINUTE) >= 30)
  c.add(Calendar.HOUR, 1);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
return c.getTime();
origin: loklak/loklak_server

  public static void main(String[] args) {
    Calendar calendar = new GregorianCalendar();
    System.out.println("the date is           : " + calendar.getTime().getTime());
    System.out.println("the timezoneOffset is : " + getTimezoneOffset());
    String postDate = toPostDate(calendar.getTime());
    System.out.println("the post date is      : " + postDate);
    try {
      System.out.println("post date to date     : " + parse(postDate, getTimezoneOffset()).getTime().getTime());
    } catch (ParseException e) {
      e.printStackTrace();
    }
  }
}
origin: stackoverflow.com

 Calendar mydate = new GregorianCalendar();
String mystring = "January 2, 2010";
Date thedate = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH).parse(mystring);
mydate.setTime(thedate);
//breakdown
System.out.println("mydate -> "+mydate);
System.out.println("year   -> "+mydate.get(Calendar.YEAR));
System.out.println("month  -> "+mydate.get(Calendar.MONTH));
System.out.println("dom    -> "+mydate.get(Calendar.DAY_OF_MONTH));
System.out.println("dow    -> "+mydate.get(Calendar.DAY_OF_WEEK));
System.out.println("hour   -> "+mydate.get(Calendar.HOUR));
System.out.println("minute -> "+mydate.get(Calendar.MINUTE));
System.out.println("second -> "+mydate.get(Calendar.SECOND));
System.out.println("milli  -> "+mydate.get(Calendar.MILLISECOND));
System.out.println("ampm   -> "+mydate.get(Calendar.AM_PM));
System.out.println("hod    -> "+mydate.get(Calendar.HOUR_OF_DAY));
origin: stackoverflow.com

 import java.util.GregorianCalendar;

import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

public class DateTest {

  public static void main(final String[] args) throws Exception {
   GregorianCalendar gcal = new GregorianCalendar();
   XMLGregorianCalendar xgcal = DatatypeFactory.newInstance()
      .newXMLGregorianCalendar(gcal);
   System.out.println(xgcal);
  }

}
origin: redisson/redisson

public Date getTimeAfter(Date afterTime) {
  Calendar cl = new java.util.GregorianCalendar(getTimeZone()); 
  cl.setTime(afterTime);
  cl.set(Calendar.MILLISECOND, 0);
    if(cl.get(Calendar.YEAR) > 2999) { // prevent endless loop...
      return null;
    int t = 0;
    int sec = cl.get(Calendar.SECOND);
    int min = cl.get(Calendar.MINUTE);
      sec = seconds.first();
      min++;
      cl.set(Calendar.MINUTE, min);
    cl.set(Calendar.SECOND, sec);
    min = cl.get(Calendar.MINUTE);
              mon = 1;
              tmon = 3333; // ensure test of mon != tmon further below fails
              cl.add(Calendar.YEAR, 1);
  return cl.getTime();
origin: stackoverflow.com

 import java.util.GregorianCalendar;

public class RandomDateOfBirth {

  public static void main(String[] args) {

    GregorianCalendar gc = new GregorianCalendar();

    int year = randBetween(1900, 2010);

    gc.set(gc.YEAR, year);

    int dayOfYear = randBetween(1, gc.getActualMaximum(gc.DAY_OF_YEAR));

    gc.set(gc.DAY_OF_YEAR, dayOfYear);

    System.out.println(gc.get(gc.YEAR) + "-" + (gc.get(gc.MONTH) + 1) + "-" + gc.get(gc.DAY_OF_MONTH));

  }

  public static int randBetween(int start, int end) {
    return start + (int)Math.round(Math.random() * (end - start));
  }
}
origin: spring-projects/spring-framework

Calendar calendar = new GregorianCalendar();
calendar.setTimeZone(this.timeZone);
calendar.setTime(date);
calendar.set(Calendar.MILLISECOND, 0);
long originalTimestamp = calendar.getTimeInMillis();
doNext(calendar, calendar.get(Calendar.YEAR));
  calendar.add(Calendar.SECOND, 1);
  doNext(calendar, calendar.get(Calendar.YEAR));
return calendar.getTime();
origin: kiegroup/jbpm

Calendar tmpFrom = new GregorianCalendar();
if (timezone != null) {
  tmpFrom.setTimeZone(TimeZone.getTimeZone(timezone));
tmpFrom.setTime(sdf.parse(fromTo[0]));
Calendar tmpTo = new GregorianCalendar();
if (timezone != null) {
  tmpTo.setTimeZone(TimeZone.getTimeZone(timezone));
tmpTo.setTime(sdf.parse(fromTo[1]));
Date from = tmpFrom.getTime();
tmpTo.add(Calendar.DAY_OF_YEAR, 1);
if ((tmpFrom.get(Calendar.MONTH) > tmpTo.get(Calendar.MONTH)) && (tmpFrom.get(Calendar.YEAR) == tmpTo.get(Calendar.YEAR))) {
  tmpTo.add(Calendar.YEAR, 1);
  tmpFrom = new GregorianCalendar();
  if (timezone != null) {
    tmpFrom.setTimeZone(TimeZone.getTimeZone(timezone));
  from = tmpFrom.getTime();
  tmpTo = new GregorianCalendar();
  if (timezone != null) {
    tmpTo.setTimeZone(TimeZone.getTimeZone(timezone));
Calendar c = new GregorianCalendar();
origin: blynkkk/blynk-server

/**
 * Sets the Date header for the HTTP response
 *
 * @param response
 *            HTTP response
 */
private static void setDateHeader(FullHttpResponse response) {
  SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
  dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE));
  Calendar time = new GregorianCalendar();
  response.headers().set(DATE, dateFormatter.format(time.getTime()));
}
origin: jaydenxiao2016/AndroidFire

/**
 * 描述:获取本月第一天.
 *
 * @param format the format
 * @return String String类型日期时间
 */
public static String getFirstDayOfMonth(String format) {
  String strDate = null;
  try {
    Calendar c = new GregorianCalendar();
    SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
    //当前月的第一天
    c.set(GregorianCalendar.DAY_OF_MONTH, 1);
    strDate = mSimpleDateFormat.format(c.getTime());
  } catch (Exception e) {
    e.printStackTrace();
  }
  return strDate;
}
origin: stackoverflow.com

 Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2014);
cal.set(Calendar.DAY_OF_YEAR, 1);    
Date start = cal.getTime();

//set date to last day of 2014
cal.set(Calendar.YEAR, 2014);
cal.set(Calendar.MONTH, 11); // 11 = december
cal.set(Calendar.DAY_OF_MONTH, 31); // new years eve

Date end = cal.getTime();

//Iterate through the two dates 
GregorianCalendar gcal = new GregorianCalendar();
gcal.setTime(start);
while (gcal.getTime().before(end)) {
  gcal.add(Calendar.DAY_OF_YEAR, 1);
  //Do Something ...
}
origin: stackoverflow.com

 Long gmtTime =1317951113613L; // 2.32pm NZDT
Long timezoneAlteredTime = 0L;

if (offset != 0L) {
  int multiplier = (offset*60)*(60*1000);
  timezoneAlteredTime = gmtTime + multiplier;
} else {
  timezoneAlteredTime = gmtTime;
}

Calendar calendar = new GregorianCalendar();
calendar.setTimeInMillis(timezoneAlteredTime);

DateFormat formatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss z");

formatter.setCalendar(calendar);
formatter.setTimeZone(TimeZone.getTimeZone(timeZone));

String newZealandTime = formatter.format(calendar.getTime());
origin: stackoverflow.com

Calendar c = new GregorianCalendar();
 c.set(Calendar.HOUR_OF_DAY, 0); //anything 0 - 23
 c.set(Calendar.MINUTE, 0);
 c.set(Calendar.SECOND, 0);
 Date d1 = c.getTime(); //the midnight, that's the first second of the day.
origin: kiegroup/jbpm

protected void handleHoliday(Calendar c, boolean resetTime) {
  if (!holidays.isEmpty()) {
    Date current = c.getTime();
    for (TimePeriod holiday : holidays) {
      // check each holiday if it overlaps current date and break after first match
      if (current.after(holiday.getFrom()) && current.before(holiday.getTo())) {
        
        Calendar tmp = new GregorianCalendar();
        tmp.setTime(holiday.getTo());   
        
        Calendar tmp2 = new GregorianCalendar();
        tmp2.setTime(current);
        tmp2.set(Calendar.HOUR_OF_DAY, 0);
        tmp2.set(Calendar.MINUTE, 0);
        tmp2.set(Calendar.SECOND, 0);
        tmp2.set(Calendar.MILLISECOND, 0);
        long difference = tmp.getTimeInMillis() - tmp2.getTimeInMillis();
        
        c.add(Calendar.HOUR_OF_DAY, (int) (difference/HOUR_IN_MILLIS));
        
        handleWeekend(c, resetTime);
        break;
      }
    }
  }
  
}
origin: DiUS/java-faker

/**
 * Generates a random birthday between two ages.
 *
 * @param minAge
 *            the minimal age
 * @param maxAge
 *            the maximal age
 * @return a random birthday between {@code minAge} and {@code maxAge} years ago.
 * @throws IllegalArgumentException
 *             if the {@code maxAge} is lower than {@code minAge}.
 */
public Date birthday(int minAge, int maxAge) {
  int currentYear = Calendar.getInstance().get(Calendar.YEAR);
  Calendar from = new GregorianCalendar(currentYear - maxAge, 0, 1);
  Calendar to = new GregorianCalendar(currentYear - minAge, 11, 31);
  return between(from.getTime(), to.getTime());
}
java.utilGregorianCalendar<init>

Javadoc

Constructs a new GregorianCalendar initialized to the current date and time with the default Locale and TimeZone.

Popular methods of GregorianCalendar

  • getTime
  • setTime
  • get
  • set
  • getTimeInMillis
  • setTimeInMillis
  • add
  • getInstance
  • setTimeZone
  • clear
  • getTimeZone
  • isLeapYear
    Returns true if year is a leap year.
  • getTimeZone,
  • isLeapYear,
  • setGregorianChange,
  • from,
  • getActualMaximum,
  • getGregorianChange,
  • before,
  • clone,
  • setLenient

Popular in Java

  • Start an intent from android
  • putExtra (Intent)
  • requestLocationUpdates (LocationManager)
  • getSharedPreferences (Context)
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • ReentrantLock (java.util.concurrent.locks)
    A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor
  • JButton (javax.swing)
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now