Skip to main content

Calendar Test- A Simple Java Code

import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;
 
public class CalendarTest {
   public static void main(String[] args) {
      Calendar cal = Calendar.getInstance();   // GregorianCalendar
      System.out.println("Calendar's toString() is : " + cal + "\n");
      System.out.println("Time zone is: " + cal.getTimeZone() + "\n");
 
      // An Easier way to print the timestamp by getting a Date instance
      Date date = cal.getTime();
      System.out.println("Current date and time in Date's toString() is : " + date + "\n");
 
      // Print Calendar's field
      System.out.println("Year  : " + cal.get(Calendar.YEAR));
      System.out.println("Month : " + cal.get(Calendar.MONTH));
      System.out.println("Day of Month : " + cal.get(Calendar.DAY_OF_MONTH));
      System.out.println("Day of Week  : " + cal.get(Calendar.DAY_OF_WEEK));
      System.out.println("Day of Year  : " + cal.get(Calendar.DAY_OF_YEAR));
      System.out.println("Week of Year : " + cal.get(Calendar.WEEK_OF_YEAR));
      System.out.println("Week of Month : " + cal.get(Calendar.WEEK_OF_MONTH));
      System.out.println("Day of the Week in Month : " + cal.get(Calendar.DAY_OF_WEEK_IN_MONTH));
      System.out.println("Hour  : " + cal.get(Calendar.HOUR));
      System.out.println("AM PM : " + cal.get(Calendar.AM_PM));
      System.out.println("Hour of the Day : " + cal.get(Calendar.HOUR_OF_DAY));
      System.out.println("Minute : " + cal.get(Calendar.MINUTE));
      System.out.println("Second : " + cal.get(Calendar.SECOND));
      System.out.println();
 
      // Manipulating Dates
      Calendar calTemp;
      calTemp = (Calendar) cal.clone();
      calTemp.add(Calendar.DAY_OF_YEAR, -365);
      System.out.println("365 days ago, it was: " + calTemp.getTime());

      calTemp = (Calendar) cal.clone();
      calTemp.add(Calendar.HOUR_OF_DAY, 11);
      System.out.println("After 11 hours, it will be: " + calTemp.getTime());

      // Roll
      calTemp = (Calendar) cal.clone();
      calTemp.roll(Calendar.HOUR_OF_DAY, 11);
      System.out.println("Roll 11 hours, it will be: " + calTemp.getTime());
      System.out.println();
   }
}

Comments

Popular posts from this blog

Banking (ICSE Class 10 Mathematics Project)

BANK ACCOUNT A bank account is a financial account between a bank customer and a financial institution. A bank account can be a deposit account, a credit card, or any other type of account offered by a financial institution. The financial transactions which have occurred within a given period of time on a bank account are reported to the customer on a bank statement and the balance of the account at any point in time is the financial position of the customer with the institution. a fund that a customer has entrusted to a bank and from which the customer can make withdrawals. BANK A bank is a financial institution and a financial intermediary that accepts deposits and channels those deposits into lending activities, either directly by loaning or indirectly through capital markets. A bank links together customers that have capital deficits and customers with capital surplu...

Sarvepalli Radhakrishnan- Class 10 History ICSE Project

Sarvepalli Radhakrishnan Sarvepalli Radhakrishnan listen    (5 September 1888 – 17 April 1975) was an Indian philosopher and statesman who served as the first Vice President of India (1952–1962) and the second President of India (1962-1967). Sarvepalli Radhakrishnan was born on September 5, 1888 at Tirutani, Madras in a poor Brahmin family. As his father was poor Radhakrishnan supported most of his education through scholarships.  His father worked as a subordinate revenue official in the service of a local zamindar (landlord) and the family was a modest one. He did not want his son to receive an English education and wanted him to become a priest. But life had other plans for the young boy.   Dr. Sarvepalli Radhakrishnan had his early education at Gowdie School, Tiruvallur and then went to the Lutheran Mission School in Tirupati for his high school. He joined the Voorhee's College in Vellore and later switched to the Madras Christian College. He chose Philo...

BlueStacks

BlueStacks Industry Virtualization ,  mobile software Founded April 2009 ; 8 years ago Founders Rosen Sharma, Jay Vaishnav, Suman Saraf Headquarters Campbell, California , United States Products App Player, GamePop Website www .bluestacks .com BlueStacks App Player Bluestack Client with Android  home screen  open as of September 2014. Stable release 2.7.315.8233 Development status Active Operating system Windows  XP or later;  Mac OS X  Mavericks or later Platform IA-32 Size 307  MB Available in 47 languages Type Android emulator License Freeware Website www .bluestacks .co m Bluestacks  is an  American  technology company that produces the BlueStacks App Player and other  cloud -based  cross-platform  products. The BlueStacks App Player is designed to enable  Android  applications to run on PCs running  Microsoft Windows  and  macOS . The company was...