Code example for GregorianCalendar

Methods: setTime, setTimeZone

0
    } 
     
    public static String getCurrentTime() {
    	 
        // Create a calendar to work with.  
        GregorianCalendar gc = new GregorianCalendar(Locale.US); 
        // Create a timezone object to set ont eh calendar.  
        TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); 
        // Set the timezone.  
        gc.setTimeZone(tz); 
        // Set the date.  
        gc.setTime(new Date()); 
        // Format the date  
        SimpleDateFormat sdf = new SimpleDateFormat("dd MMMMM yyyy, H:mm:ss:FF");
 
        // Give the date format a calendar to work with.  
        sdf.setCalendar(gc); 
        // Create a string out of the date for display on the page.  
        String sDate = sdf.format(sdf.getCalendar().getTime()); 
         
        return sDate;