Results 1 to 3 of 3

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

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

  2. #2
    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(“c2 =”+c2.getTimeInMillis());

    //Using Calendar Object to Convert date from one TimeZone to another TimeZone
    Calendar c3 = Calendar.getInstance(TimeZone.getTimeZone(“America/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(“c3 =”+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(‘en’,'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(“pattern”,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(“yyyy.MM.dd G ‘at’ HH:mm:ss Z”,l2);
    System.out.println(“In the present Time Zone”);
    System.out.println(sdf.format(d));

  3. #3
    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 ^_^

Similar Threads

  1. pls convert this c++ to java code
    By xSim21 in forum Software Development
    Replies: 4
    Last Post: 26-03-2012, 06:32 PM
  2. help with java code
    By unikshegz in forum Software Development
    Replies: 2
    Last Post: 24-10-2010, 02:47 PM
  3. Use Java code in PHP
    By Gajendra1 in forum Software Development
    Replies: 6
    Last Post: 12-08-2010, 10:18 AM
  4. Java error in I/O Code
    By Viensterrr in forum Software Development
    Replies: 5
    Last Post: 18-01-2010, 05:03 PM
  5. Java code for button
    By Owen Fernandes in forum Software Development
    Replies: 5
    Last Post: 06-01-2010, 02:39 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,724,884.17034 seconds with 17 queries