Example usage for java.util GregorianCalendar GregorianCalendar

List of usage examples for java.util GregorianCalendar GregorianCalendar

Introduction

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

Prototype

GregorianCalendar(TimeZone zone, Locale locale, boolean flag) 

Source Link

Document

Constructs an empty GregorianCalendar.

Usage

From source file:PriorityQueueTest.java

public static void main(String[] args) {
    PriorityQueue<GregorianCalendar> pq = new PriorityQueue<GregorianCalendar>();
    pq.add(new GregorianCalendar(1906, Calendar.DECEMBER, 9)); // G. Hopper
    pq.add(new GregorianCalendar(1815, Calendar.DECEMBER, 10)); // A. Lovelace
    pq.add(new GregorianCalendar(1903, Calendar.DECEMBER, 3)); // J. von Neumann
    pq.add(new GregorianCalendar(1910, Calendar.JUNE, 22)); // K. Zuse

    System.out.println("Iterating over elements...");
    for (GregorianCalendar date : pq)
        System.out.println(date.get(Calendar.YEAR));
    System.out.println("Removing elements...");
    while (!pq.isEmpty())
        System.out.println(pq.remove().get(Calendar.YEAR));
}

From source file:DatePrint1.java

public static void main(String[] argv) {
    //+//from  w w  w . j  av  a2s.  c  o m
    Calendar c = new GregorianCalendar(1918, 10, 11);
    System.out.println(c.get(Calendar.DAY_OF_MONTH) + " " + c.get(Calendar.MONTH) + ", " + c.get(Calendar.YEAR)
            + " " + c.get(Calendar.ERA));
    //-
}

From source file:com.home.ln_spring.ch8.sample.AnnotationJdbcDaoSample.java

public static void main(String[] args) {

    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load("classpath:ch8/app-context-annotation.xml");
    context.refresh();//from w w w .  j a va2 s  . c o m

    ContactDao contactDao = context.getBean("contactDao", ContactDao.class);
    List<Contact> contacts = contactDao.findAll();
    listContacts(contacts);

    System.out.println("Find by first name: ");

    contacts = contactDao.findByFirstName("Clarence");
    listContacts(contacts);

    //        System.out.println("Update contact with id : ");
    //        Contact contact = new Contact();
    //        contact.setId(2);
    //        contact.setFirstName("Jack");
    //        contact.setLastName("Rodwell");
    //        contact.setBirthDate(
    //                new Date((new GregorianCalendar(1987, 1, 8)).getTime().getTime()));
    //        contactDao.update(contact);
    //        
    //        contacts = contactDao.findAll();
    //        listContacts(contacts);

    //        System.out.println("Insert contact");
    //        System.out.println();
    //        Contact contact1 = new Contact();
    //        contact1.setFirstName("Rod");
    //        contact1.setLastName("Johnson");
    //        contact1.setBirthDate(
    //                new Date((new GregorianCalendar(1987, 1, 8)).getTime().getTime()));
    //        contactDao.insert(contact1);
    //        
    //        contacts = contactDao.findAll();
    //        listContacts(contacts);

    System.out.println("Insert with BatchSqlUpdate");
    System.out.println();
    Contact contact2 = new Contact();
    contact2.setFirstName("Michael");
    contact2.setLastName("Jackson");
    contact2.setBirthDate(new Date((new GregorianCalendar(1964, 10, 1)).getTime().getTime()));

    List<ContactTelDetail> contactTelDetails = new ArrayList<ContactTelDetail>();
    ContactTelDetail contactTelDetail = new ContactTelDetail();
    contactTelDetail.setTelType("Home");
    contactTelDetail.setTelNumber("111111");
    contactTelDetails.add(contactTelDetail);
    contactTelDetail = new ContactTelDetail();
    contactTelDetail.setTelType("Mobile");
    contactTelDetail.setTelNumber("222222");
    contactTelDetails.add(contactTelDetail);
    contact2.setContactTelDetails(contactTelDetails);
    contactDao.insertWithDetail(contact2);
    contacts = contactDao.findAllWithDetail();
    listContacts(contacts);
}

From source file:Main.java

public static GregorianCalendar createGregorianCalendar(int _year, int _month, int _day) {
    return new GregorianCalendar(_year, _month - 1, _day);
}

From source file:Main.java

public static String getPrettyDate(int year, int month, int day) {
    Calendar c = new GregorianCalendar(year, month, day);
    DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG);
    return dateFormat.format(c.getTime());
}

From source file:Main.java

public static String getReadableDate(int year, int month, int day) {
    Calendar theCalendar = new GregorianCalendar(year, month, day);
    String monthString = getMonthNames(month);
    String result = day + " " + monthString + " " + year;
    return result;
}

From source file:Main.java

public static long currentYearInMills() {
    GregorianCalendar gregoriancalendar = new GregorianCalendar((new GregorianCalendar()).get(1), 1, 1);
    gregoriancalendar.setTimeZone(GMT);/*from www .  j  av a2 s .  co  m*/
    return gregoriancalendar.getTimeInMillis();
}

From source file:Main.java

public static int getDatePeriod(String startDate, String endDate) {

    String[] date1 = startDate.split("-");
    String[] date2 = endDate.split("-");
    GregorianCalendar gc1 = new GregorianCalendar(Integer.parseInt(date1[0]), Integer.parseInt(date1[1]),
            Integer.parseInt(date1[2]));
    GregorianCalendar gc2 = new GregorianCalendar(Integer.parseInt(date2[0]), Integer.parseInt(date2[1]),
            Integer.parseInt(date2[2]));
    long longDate1 = gc1.getTimeInMillis();
    long longDate2 = gc2.getTimeInMillis();
    long period = longDate2 - longDate1;
    period /= 24 * 60 * 60 * 1000;// w  ww . j a va  2  s. c  o m
    return (int) period;
}

From source file:Main.java

/**
 * CPLC dates are counted in days starting from "1986-02-04"
 * /*from ww w. j a v  a  2s  . c o  m*/
 * @param cplcDateValue
 * @return
 */
public static Calendar getDateFromCPLCDateValue(int cplcDateValue) {
    GregorianCalendar startDay = new GregorianCalendar(1977, 11, 29);
    startDay.add(Calendar.DAY_OF_YEAR, cplcDateValue);
    return startDay;
}

From source file:Main.java

public static int getDayWeek(int index) {
    int year = MIN_YEAR + index / 12;
    int month = index % 12;
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Calendar date = new GregorianCalendar(year, month, 1);
    int dayweek = date.get(Calendar.DAY_OF_WEEK);
    return dayweek;

}