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 surpluses. The word bank was borrowed in Middle English from Middle French banque, from Old Italian banca

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 Philosophy as his ma

ICSE Class X - Math Project (Types of Bank Accounts in India)

Types of Bank Accounts in India With the advancement in banking technology, many banks are offering tailor made products to suit individual needs. While accounts may differ from bank to bank their purpose remain the same. Many banks have different products on the basis of customer's age, income and gender. Here are a few different kinds of bank accounts. There are mainly three types of Banking accounts in India: Demand Deposits Term Deposits Non-Resident Deposits Now, we will study one by one, starting from Demand Deposits. 1. Demand Deposit In these types of accounts, money is payable on demand. It includes current accounts and savings accounts ( CASA - Current Account and Savings Account ) (A)  Savings account:  A savings account is an interest-bearing account held at a bank.   There are mainly three types of saving accounts in Indian banks:          (i) Basic Savings Bank Deposit Accounts (BSBDA)          (ii) Basic Saving Bank Deposit Acco