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...

WALL OF THORAX-Anatomy Notes

1 WALL OF THORAX DESCRIBE COURSE, BRANCHES AND DISTRIBUTION OF TYPICAL INTERCOSTAL NERVE (LE). There are 12 thoracic spinal nerves. The 3 rd  to 6th nerves lie in typical intercostal spaces between typical ribs. They are confined to the thoracic wall. Formation: The thoracic spinal nerve is formed by anterior and posterior roots, which arises from the anterior and posterior horns of spinal cord respectively. The anterior and posterior roots join together to form the trunk. The trunk divides into anterior and posterior rami. The anterior ramus forms the intercostal nerve. Course: The nerve passes through the respective intervertebral foramen and appears in the posterior part of the intercostal spaces. On reaching the angle of the upper rib, the trunk of the nerve passes forwards along the costal groove between intercostalis internus and intimus muscle. Intercostal nerves runs in the costal groove and ends near the sternum. 2 In the costal groove...

KARYOTYPE

 A karyotype refers to a full set of chromosomes from an individual arranged according to length, position of centromere, banding pattern.  Karyotype is written as total number of chromosomes followed by sex chromosomes  Normal male karyotype: 46,XY, normal female karyotype: 46,XX  Chromosomes are classified into 7 groups and pasted accordingly- Group A- 1, 2, 3; group B- 4, 5; group C- 6-12, X; group D- 13, 14, 15; group E- 16, 17, 18; group F- 19, 20; group G- 21, 22, Y