Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



help me to understand java code (calendar java code) ?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 09-01-2011
Member
 
Join Date: Jan 2011
Posts: 2
help me to understand java code (calendar java code) ?
  

hi
i need some one explain java code (calendar java code)
i study java now .... and i hava final lap exam tomoroow
this is my code
PHP Code:
import javax.swing.*;  
 
import java.util.*;  
 
import java.text.*;  

   public class 
EnglishCalendar   
      
{       
          public static 
String[] months = {  
           
"January" "February" "March",  
           
"April" "May" "June",  
           
"July" "August" "September",  
            
"October" "November" "December" 
           
};  
       public static 
int days[] = {  
         
312831,  
         
303130,
         
313130,  
         
313031 
        
};  

        private 
void showMonth(int mint y) {  
        
int lead_spaces 0;  
          if (
|| 11) {  
        
System.out.println("It should be 1 to 12");  
            }  
         else {  
             
System.out.println();  
             
System.out.println("    " months[m] + " " y);  
             
System.out.println();  
             
GregorianCalendar cal = new GregorianCalendar(ym0);  
             
System.out.println("Su Mo Tu We Th Fr Sa ");  
             
lead_spaces cal.get(Calendar.DAY_OF_WEEK);  
             
int day_of_month days[m];  
             if (
cal.isLeapYear(cal.get(Calendar.YEAR)) && == 1){ day_of_month++;}  
             for (
int i 0lead_spacesi++) {  
                 
System.out.print("   ");  
                  }  
             for (
int i 1<= day_of_monthi++) {  
                if (
10System.out.print(" ");  
                  
System.out.print(i);  
                if ((
lead_spaces  i) % == 0) {  
                   
System.out.println();  
                     }   
                   else {
                   
System.out.print(" ");  
                }  } 
             
System.out.println();   }  }  
      
      private static 
void doSimpleDateFormat() {  
        
Calendar now Calendar.getInstance();  
        
SimpleDateFormat formatter = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz");  
        
System.out.print(" \n It is now : " formatter.format(now.getTime()));  
         
System.out.println();  
              }  
        public static 
void main(String[] args) {  
            
String mo JOptionPane.showInputDialog("Month");  
            
String ye JOptionPane.showInputDialog("Year");  
            
int mon = new Integer(mo).intValue();  
            
int yea = new Integer(ye).intValue();  
              
EnglishCalendar k = new EnglishCalendar();  
                  
k.showMonth(mon yea);  
             
doSimpleDateFormat();  
}  

   } 
i hope any one explain the code above and how it is execute

Reply With Quote
  #2  
Old 09-01-2011
Member
 
Join Date: Dec 2007
Posts: 2,291
Re: help me to understand java code (calendar java code) ?

The main purpose of Calendar is to represent the GMT in various Calendars , various TimeZones. By default Gegorian Calendar is being used all over the world.

Please follow the below snippet to understand
覧覧覧覧覧覧覧覧-
System.out.println(点_______________________All about Calendar Classes________________________________________);
//By default it will get the Gegorian Calendar and intialize with the current datetime related to the default timezone in which you are
Calendar c2 = Calendar.getInstance();
System.out.println(c2.getTimeZone().getDisplayName());
System.out.println(c2.get(Calendar.HOUR));
System.out.println(c2.get(Calendar.MINUTE));
System.out.println(田2 =+c2.getTimeInMillis());

//Using Calendar Object to Convert date from one TimeZone to another TimeZone
Calendar c3 = Calendar.getInstance(TimeZone.getTimeZone(鄭merica/Los_Angeles));
c3.setTimeInMillis(c2.getTimeInMillis());
System.out.println(c3.getTimeZone().getDisplayName());
System.out.println(c3.get(Calendar.HOUR));
System.out.println(c3.get(Calendar.MINUTE));
System.out.println(田3 =+c3.getTimeInMillis());

Locale

One of the Locale Object Constructor is Locale(language,Country);
Locale is used to capture the Locality information of where the user is being present.
new Locale(粗n,'IN) //represents the Locale object intialized with the India Locality.
there is default locale object which is being intialized at the start of the JVM.
This locale object is being used when displaying the local sensitive information such as date and others.

new SimpleDateFormat(菟attern,new Locale(language,CountryCode));
the above format is being used to display the date in the pattern which was given in the constructor
while displaying this SimpleDateFormat also considers the Locale Object too to display the same pattern as per the taste
of local people.

Code snippet
覧覧
Date d = new Date(); //created the date object
SimpleDateFormat sdf = new SimpleDateFormat(土yyy.MM.dd G 疎t HH:mm:ss Z,l2);
System.out.println(的n the present Time Zone);
System.out.println(sdf.format(d));
Reply With Quote
  #3  
Old 10-01-2011
Member
 
Join Date: Jan 2011
Posts: 2
Re: help me to understand java code (calendar java code) ?

thank you for help
but if you can explain this :
HTML Code:
import javax.swing.*;   
 import java.util.*;   
 import java.text.*;   
and tow method below:

PHP Code:
public class EnglishCalendar    
      
{        
          public static 
String[] months = {   
           
"January" "February" "March",   
           
"April" "May" "June",   
           
"July" "August" "September",   
            
"October" "November" "December"  
           
};   
              private 
void showMonth(int mint y) {   
        
int lead_spaces 0;   
          if (
|| 11) {   
        
System.out.println("It should be 1 to 12");   
            }   
         else {   
             
System.out.println();   
             
System.out.println("    " months[m] + " " y);   
             
System.out.println();   
             
GregorianCalendar cal = new GregorianCalendar(ym0);   
             
System.out.println("Su Mo Tu We Th Fr Sa ");   
             
lead_spaces cal.get(Calendar.DAY_OF_WEEK);   
             
int day_of_month days[m];   
             if (
cal.isLeapYear(cal.get(Calendar.YEAR)) && == 1){ day_of_month++;}   
             for (
int i 0lead_spacesi++) {   
                 
System.out.print("   ");   
                  }   
             for (
int i 1<= day_of_monthi++) {   
                if (
10System.out.print(" ");   
                  
System.out.print(i);   
                if ((
lead_spaces  i) % == 0) {   
                   
System.out.println();   
                     }    
                   else { 
                   
System.out.print(" ");   
                }  }  
             
System.out.println();   }  } 
thanks so mutch ^_^
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "help me to understand java code (calendar java code) ?"
Thread Thread Starter Forum Replies Last Post
pls convert this c++ to java code xSim21 Software Development 4 26-03-2012 06:32 PM
help with java code unikshegz Software Development 2 24-10-2010 02:47 PM
Use Java code in PHP Gajendra1 Software Development 6 12-08-2010 10:18 AM
Java error in I/O Code Viensterrr Software Development 5 18-01-2010 05:03 PM
Java code for button Owen Fernandes Software Development 5 06-01-2010 02:39 PM


All times are GMT +5.5. The time now is 06:11 AM.