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

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

X CHROMOSOME

X CHROMOSOME   The X chromosome is one of the two sex-determining chromosomes and is found in both males and females.  It is submetacentric chromosome classified under ‘C’ group chromosomes  Females have two X chromosomes, whereas males have one X and one Y chromosome.  Both males and females retain one of their mother's X chromosomes, and females retain their second X chromosome from their father.  Early in embryonic development in females, one of the two X chromosomes is randomly and permanently inactivated in nearly all somatic cells. This phenomenon is called X-inactivation or Lyonization. The inactive X- chromosome is tightly coiled and hence stains dark purple and is seen as Barr body within the nucleus of a female. The X chromosome is notably larger and has a more active euchromatin region.  Numerical alteration in Sex chromosomes result in abnormalities eg Turner’s syndrome (XO), Klinefelter’s syndrome (XXY) and Triple X syndrome (XXX).  , S...