Showing posts with label DateTime. Show all posts
Showing posts with label DateTime. Show all posts

Tuesday, December 18, 2012

Convert Seconds into HH:MM:SS in java?

Below are the methods to convert seconds into minute seconds format...


int day = (int)TimeUnit.SECONDS.toDays(seconds);      
long hours = TimeUnit.SECONDS.toHours(seconds) - (day *24);
long minute = TimeUnit.SECONDS.toMinutes(seconds) - (TimeUnit.SECONDS.toHours(seconds)* 60);
long second = TimeUnit.SECONDS.toSeconds(seconds) - (TimeUnit.SECONDS.toMinutes(seconds) *60);
 System.out.println("Random Element "+minute+":"+second);

OR 

public static void calculateTime(long seconds) {
   int day = (int) TimeUnit.SECONDS.toDays(seconds);
   long hours = TimeUnit.SECONDS.toHours(seconds) -
                TimeUnit.DAYS.toHours(day);
   long minute = TimeUnit.SECONDS.toMinutes(seconds) -
                 TimeUnit.DAYS.toMinutes(day) -
                 TimeUnit.HOURS.toMinutes(hours);
   long second = TimeUnit.SECONDS.toSeconds(seconds) -
                 TimeUnit.DAYS.toSeconds(day) -
                 TimeUnit.HOURS.toSeconds(hours) -
                 TimeUnit.MINUTES.toSeconds(minute);
   System.out.println("Day " + day + " Hour " + hours + " Minute " + minute + " Seconds " + second);
}

Monday, May 14, 2012

Set “date” with two ways: in Android ?


First Way:
If you are retrieving date directly from db then take it in String
Then check whether there that date is null or not.
Like shown below:
String strRequiredDate = ClassObject.getMyDate();
if(strExpirationDate != null)
{
String strDate;
SimpleDateFormat objDateFormat;
Date objDate;
objDateFormat = new SimpleDateFormat(“dd MMM yyyy HH:mm”);
objDateFormat.setTimeZone(Calendar.getInstance().getTimeZone());
objDate = objDateFormat.parse(strRequiredDate);
strDate = DateFormat.getDateFormat(getApplicationContext()).format(objDate);
objDateFormat = new SimpleDateFormat(“hh:mm aaa”);
objDateFormat.setTimeZone(Calendar.getInstance().getTimeZone());
strDate = strDate + “  ” + objDateFormat.format(objDate);
btnPickDateTime.setText(strDate);
btnPickDateTime.setVisibility(View.VISIBLE);
}
Output:
04/01/2013 09:35 AM

Second Way:
SimpleDateFormat formatter;
Date objDate = new Date();
//Date values
int year;
int dayOfMonth;
int monthOfYear;
//Time values
int hour;
int min;
year = objDatePicker.getYear() – 1900;
dayOfMonth = objDatePicker.getDayOfMonth();
monthOfYear = objDatePicker.getMonth();
hour = objTimePicker.getCurrentHour();
min = objTimePicker.getCurrentMinute();
objDate.setDate(dayOfMonth);
objDate.setMonth(monthOfYear);
objDate.setYear(year);
objDate.setHours(hour);
objDate.setMinutes(min);
_objExpiryDate = objDate;
formatter=new SimpleDateFormat(DATE_FORMAT);
btnPickDateTime.setText(formatter.format(objDate));
Where as objDatePicker is nothing but my DatePicker control to select the perticular date.
objTimePicker is nothing but my TimePicker control to select the perticular time.
Output:
4 Jan 2013 09:35

Tuesday, March 27, 2012

How to convert Date and Time in Millisecond in android?


public long dateConvertor(String date) throws ParseException {
Date currentpastDate = null;
try {
SimpleDateFormat formatter = new SimpleDateFormat("d MMM yyyy h:mm a");
currentpastDate = (Date) formatter.parse(date);


} catch (Exception E) {
E.printStackTrace();
}
return currentpastDate.getTime();
}

Sunday, March 18, 2012

How to get list of calendars in android 4.0?


 // Get list of Calendars 


        ContentResolver contentResolver = ctx.getContentResolver();
        Log.d(MainActivity.TAG, "URI = " + CalendarContract.Calendars.CONTENT_URI);
        final Cursor cursor = contentResolver.query(CalendarContract.Calendars.CONTENT_URI,
        CALENDAR_QUERY_COLUMNS, null, null, null);
        Log.d(MainActivity.TAG, "cursor = " + cursor);
        while (cursor.moveToNext()) {
        final String _id = cursor.getString(0);
        final String displayName = cursor.getString(1);
        final Boolean selected = !cursor.getString(2).equals("0");
        final String accountName = cursor.getString(3);
        Log.d(MainActivity.TAG, "Found calendar " + accountName);
        calendarList.append(
        "Calendar: Id: " + _id + " Display Name: " + displayName + " Selected: " + selected + " Name " + accountName);
        }

How to add event,reminder in Android 2.3 Calendar through code?


First of all we need to get the calendar provider uri.........
if (Build.VERSION.SDK_INT >= 8 ) {
        l_eventUri = Uri.parse("content://com.android.calendar/events");
    } else {
        l_eventUri = Uri.parse("content://calendar/events");
    }
But below the getCalendarUriBase(this) method is already return to get URI.So no need to use above code.It is just for your understanding.


You'll also need to add these permission to your manifest for this method.........
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />

/*
* A device may have more than one Calendar configure in it. So first,
* you must find out available calendar's name and their id.
 */
Cursor cursor = getContentResolver() .query(Uri.parse(getCalendarUriBase(this) ),new String[] { "calendar_id", "displayname" }, null,null, null);
cursor.moveToFirst();
// fetching calendars name
String CNames[] = new String[cursor.getCount()];
// fetching calendars id
int[] CalIds = new int[cursor.getCount()];
for (int i = 0; i < CNames.length; i++) {
CalIds[i] = cursor.getInt(0);
CNames[i] = cursor.getString(1);
cursor.moveToNext();
}



        // get calendar
        Calendar cal = Calendar.getInstance();     
        Uri EVENTS_URI = Uri.parse(getCalendarUriBase(this) + "events");
        ContentResolver cr = getContentResolver();


        // event insert
        ContentValues values = new ContentValues();
        values.put("calendar_id",CalIds);
        values.put("title", "Reminder Title");
        values.put("allDay", 0);
        values.put("dtstart", cal.getTimeInMillis() + 11*60*1000); // event starts at 11 minutes from now
        values.put("dtend", cal.getTimeInMillis()+60*60*1000); // ends 60 minutes from now
        values.put("description", "Reminder description");
        //Event Id
        values.put("_id", scheduleId);  
        //0~ default; 1~ confidential; 2~ private; 3~ public
        values.put("visibility", 0);
        //0~ false; 1~ true
        values.put("hasAlarm", 1);
        //status: 0~ tentative; 1~ confirmed; 2~ canceled
        values.put("eventStatus", 1);
    //0~ opaque, no timing conflict is allowed; 1~ transparency, allow overlap of scheduling
        values.put("transparency", 0);
        Uri event = cr.insert(EVENTS_URI, values);


        // reminder insert
        Uri REMINDERS_URI = Uri.parse(getCalendarUriBase(this) + "reminders");
        values = new ContentValues();
        values.put( "event_id", Long.parseLong(event.getLastPathSegment()));
        values.put( "method", 1 );
        values.put( "minutes", 10 );
        cr.insert( REMINDERS_URI, values );



        // for deleting event
// getContentResolver().delete(path to the content, want to delete,
// CONDITION, ARGUMENTS);
        // CONDITION + ARGUMENTS work as where condition to find a particular
 event.

getContentResolver().delete(
Uri.parse(getCalendarUriBase(this)),
"calendar_id=? and description=? and eventLocation=? ",
new String[] { String.valueOf(CalIds[0]), "Birthday Party",
"Delhi" });


getCalendarUriBase(this) is the method which provides the ContentProvider uri of Android device base on versions...........which is given below....



 private String getCalendarUriBase(Activity act) {
        String calendarUriBase = null;
        Uri calendars = Uri.parse("content://calendar/calendars");
        Cursor managedCursor = null;
        try {
            managedCursor = act.managedQuery(calendars, null, null, null, null);
        } catch (Exception e) {
        }
        if (managedCursor != null) {
            calendarUriBase = "content://calendar/";
        } else {
            calendars = Uri.parse("content://com.android.calendar/calendars");
            try {
                managedCursor = act.managedQuery(calendars, null, null, null, null);
            } catch (Exception e) {
            }
            if (managedCursor != null) {
                calendarUriBase = "content://com.android.calendar/";
            }
        }
        return calendarUriBase;
    }








How to open Add Event screen of Android Calendar through Intent code?


I don't know about the other version's but it worked for android 2.3 and 3.0.........

 /*add an event through intent, this doesn't require any permission
          just send intent to android calendar*/



        Calendar cal = Calendar.getInstance();              
        Intent intent = new Intent(Intent.ACTION_EDIT);
        intent.setType("vnd.android.cursor.item/event");
        intent.putExtra("beginTime", cal.getTimeInMillis());
        intent.putExtra("allDay", false);
        intent.putExtra("rrule", "FREQ=DAILY");
        intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
        intent.putExtra("title", "A Test Event from android app");
        intent.putExtra("allDay", 0);
    //status: 0~ tentative; 1~ confirmed; 2~ canceled
        intent.putExtra("eventStatus", 1);
    //0~ default; 1~ confidential; 2~ private; 3~ public
        intent.putExtra("visibility", 0);
    //0~ opaque, no timing conflict is allowed; 1~ transparency, allow overlap of scheduling
        intent.putExtra("transparency", 0);
    //0~ false; 1~ true
        intent.putExtra("hasAlarm", 1);
        intent.putExtra("eventLocation", "@home");
        try {
    startActivity(intent);
    } catch (Exception e) {
    Toast.makeText(this.getApplicationContext(), "Sorry, no compatible calendar is found!", Toast.LENGTH_LONG).show();
    }

Thursday, March 15, 2012

How to display Current Week in android List Activity?


When the program was written the date was 15 Mar 2012............so you will find the output below in screenshots....


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;


import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;


public class WeekDisplayActivity extends ListActivity {
ArrayList<String> dateStringArray=new ArrayList<String>();
// String[] dateStringArray;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ListAdapter adapter = createAdapter();
        setListAdapter(adapter);
    }
    
    protected ListAdapter createAdapter()
    {
   
    Calendar c = Calendar.getInstance();


// Set the calendar to monday of the current week
c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);


// Print dates of the current week starting on Monday
DateFormat df = new SimpleDateFormat("EEE dd/MM/yyyy");
for (int i = 0; i < 7; i++) {
dateStringArray.add(df.format(c.getTime()));
c.add(Calendar.DATE, 1);
}

    // Create a simple array adapter (of type string) with the test values
    ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, dateStringArray);

    return adapter;
    }
}




Below is the output..............



How to manipulate date in Android such as various formats and add or subtract certain number of days ?



//Add certain number of days to Today
       
int myDays = 3;

       
final Calendar c = Calendar.getInstance();
       
c.add(Calendar.DATE, myDays);  // number of days to add
       
int newDate =     (c.get(Calendar.YEAR) * 10000) + 
                           
((c.get(Calendar.MONTH) + 1) * 100) + 
                           
(c.get(Calendar.DAY_OF_MONTH));


//Subtract certain number of days to Today
       
int myDays = 3;

       
final Calendar c = Calendar.getInstance();
       
c.add(Calendar.DATE, (myDays * -1));  // number of days to subtract
       
int newDate =     (c.get(Calendar.YEAR) * 10000) + 
                           
((c.get(Calendar.MONTH) + 1) * 100) + 
                           
(c.get(Calendar.DAY_OF_MONTH));


//Change date format from yyyyMMdd to MM/dd/yy
       
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
           
Date date = null;
           
try {
               
date = df.parse(inputDate);
           
} catch (ParseException e) {
               
e.printStackTrace();
           
}
           
TextView dateText = (TextView) historyData.findViewById(R.id.mydate);
           
dateText.setText(DateFormat.format("MM/dd/yy",date));


//Change time format from military Hmmss to hh:mm:ss a

       
SimpleDateFormat df2 = new SimpleDateFormat("Hmmss");
           
Date date2 = null;
           
try {
               
date2 = df2.parse(inputTime);
           
} catch (ParseException e) {
               
e.printStackTrace();
           
}
           
TextView timeText = (TextView) historyData.findViewById(R.id.mytime);
           
timeText.setText(DateFormat.format("hh:mm:ss a",date2));

How to display required days ahead of current date in Android ListActivity?


Below is the Example.....................


import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;


import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;


public class WeekDisplayActivity extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ListAdapter adapter = createAdapter();
        setListAdapter(adapter);
    }
    
    protected ListAdapter createAdapter()
    {
    SimpleDateFormat curFormater = new SimpleDateFormat("EEEE, MMMM dd, yyyy"); 
         GregorianCalendar date = new GregorianCalendar();
         String[] dateStringArray = new String[7];


         for (int day = 0; day < 7; day++) {
             dateStringArray[day] = curFormater.format(date.getTime());
             date.roll(Calendar.DAY_OF_YEAR, true);
         }
   
    // Create a simple array adapter (of type string) with the test values
    ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, dateStringArray);

    return adapter;
    }
}




Below is the Screenshot of Output..........



Tuesday, March 6, 2012

How do I get number of days in a month in Java?


import java.util.Calendar;

public class MonthDaysExample 
{
    public static void main(String[] args)
    {
        // First get an instance of calendar object.
        Calendar calendar = Calendar.getInstance();
        
        // We'll set the date of the calendar to the following
        // date. We can use constant variable in the calendar
        // for months value (JANUARY - DECEMBER). Be informed that
        // month in Java started from 0 instead of 1.
        int year = 2007;
        int month = Calendar.FEBRUARY;
        int date = 1;
        // We have a new date of 2007-02-01
        calendar.set(year, month, date);
        
        // Here we get the maximum days for the date speficied
        // in the calendar. In this case we want to get the number
        // of days for february 2007
        int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        System.out.println("Max Day: " + maxDay);
        
        // Here we want to see what is the days for february on
        // a leap year.
        calendar.set(2004, Calendar.FEBRUARY, 1);
        maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        System.out.println("Max Day: " + maxDay);
    }
}

Monday, March 5, 2012

How do I get pattern string of a SimpleDateFormat in android?


To format a java.util.Date object we use the SimpleDateFormat class. To get back the string pattern that were used to format the date we can use the toPattern() method of this class.

import java.text.SimpleDateFormat;
import java.util.Date;

public class SimpleDateFormatToPattern {
    public static void main(String[] args) {
        SimpleDateFormat format = new SimpleDateFormat("EEEE, dd/MM/yyyy");

        
        // Gets a pattern string describing this date format used by the
        // SimpleDateFormat object.
        
        String pattern = format.toPattern();

        System.out.println("Pattern = " + pattern);
        System.out.println("Date    = " + format.format(new Date()));
    }
}

Below is the output..

Pattern = EEEE, dd/MM/yyyy
Date    = Thursday, 16/06/2011

How do I add hours, minutes or seconds to a date in Java?


import java.util.Calendar;

public class DateAddHour {
    public static void main(String[] args) {
        //
        // Gets a calendar using the default time zone and locale. The
        // Calendar returned is based on the current time in the default
        // time zone with the default locale.
        //
        Calendar calendar = Calendar.getInstance();
        System.out.println("Original = " + calendar.getTime());

        //
        // Substract 2 hour from the current time
        //
        calendar.add(Calendar.HOUR, -2);

        //
        // Add 30 minutes to the calendar time
        //
        calendar.add(Calendar.MINUTE, 30);

        //
        // Add 300 seconds to the calendar time
        //
        calendar.add(Calendar.SECOND, 300);

        System.out.println("Updated  = " + calendar.getTime());
    }
}

How do I convert time between timezone in Java?


import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class TimeZoneExample {
    public static void main(String[] args) {
        //
        // Create a calendar object and set it time based on the local
        // time zone
        //
        Calendar localTime = Calendar.getInstance();
        localTime.set(Calendar.HOUR, 17);
        localTime.set(Calendar.MINUTE, 15);
        localTime.set(Calendar.SECOND, 20);

        int hour = localTime.get(Calendar.HOUR);
        int minute = localTime.get(Calendar.MINUTE);
        int second = localTime.get(Calendar.SECOND);

        //
        // Print the local time
        //
      System.out.printf("Local time  : %02d:%02d:%02d\n", hour, minute, second);

        //
        // Create a calendar object for representing a Germany time zone. Then we
        // wet the time of the calendar with the value of the local time
        //
     Calendar germanyTime = new GregorianCalendar(TimeZone.getTimeZone("Germany"));
        germanyTime.setTimeInMillis(localTime.getTimeInMillis());
        hour = germanyTime.get(Calendar.HOUR);
        minute = germanyTime.get(Calendar.MINUTE);
        second = germanyTime.get(Calendar.SECOND);

        //
        // Print the local time in Germany time zone
        //
    System.out.printf("Germany time: %02d:%02d:%02d\n", hour, minute, second);
    }
}

How do I convert milliseconds value to date in android?


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class MillisecondsToDate {
    public static void main(String[] args) {
        //
        // Create a DateFormatter object for displaying date information.
        //
     DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
        
        //
        // Get date and time information in milliseconds
        //
        long now = System.currentTimeMillis();

        //
        // Create a calendar object that will convert the date and time value
        // in milliseconds to date. We use the setTimeInMillis() method of the
        // Calendar object.
        //
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(now);
        
        System.out.println(now + " = " + formatter.format(calendar.getTime()));
    }
}

How do I get the last day of a month in android?


import java.util.Calendar;

public class LastDayOfMonth {
    public static void main(String[] args) {
        //
        // Get a calendar instance
        //
        Calendar calendar = Calendar.getInstance();
        
        //
        // Get the last date of the current month. To get the last date for a
        // specific month you can set the calendar month using calendar object
        // calendar.set(Calendar.MONTH, theMonth) method.
        //      
        int lastDate = calendar.getActualMaximum(Calendar.DATE);
        
        //
        // Set the calendar date to the last date of the month so then we can
        // get the last day of the month
        //
        calendar.set(Calendar.DATE, lastDate);  
        int lastDay = calendar.get(Calendar.DAY_OF_WEEK);
        
        //
        // Print the current date and the last date of the month
        //
        System.out.println("Last Date: " + calendar.getTime());
        
        //
        // The lastDay will be in a value from 1 to 7 where 1 = monday and 7 =
        // saturday respectively.
        //
        System.out.println("Last Day : " + lastDay);    
    }
}

Sunday, March 4, 2012

How do I add or subtract a date in Android?


The java.util.Calendar allows us to do a date arithmetic function such as add or subtract a unit of time to the specified date field.
The method that done this process is the Calendar.add(int field, int amount). Where the value of the field can be Calendar.DATE, Calendar.MONTH, Calendar.YEAR. So this mean if you want to subtract in days, months or years use Calendar.DATE, Calendar.MONTH or Calendar.YEAR respectively.
In the code above we want to know what is the date back to 30 days ago.

import java.util.Calendar;

public class CalendarAddExample {
    public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();

        System.out.println("Today : " + cal.getTime());

        // Subtract 30 days from the calendar
        cal.add(Calendar.DATE, -30);
        System.out.println("30 days ago: " + cal.getTime());

        // Add 10 months to the calendar
        cal.add(Calendar.MONTH, 10);
        System.out.println("10 months later: " + cal.getTime());

        // Subtract 1 year from the calendar
        cal.add(Calendar.YEAR, -1)
        System.out.println("1 year ago: " + cal.getTime());
    }
}




Below is the output....

Today : Tue Jan 03 06:53:03 ICT 2006
30 days ago: Sun Dec 04 06:53:03 ICT 2005


How do I calculate difference in days between two dates in Android?


In the following example we are going to calculate the differences between two dates. First, you'll need to convert the date value into its corresponding value in milliseconds and then do the math calculation so we can get the difference in days, hours, minutes, etc.
For example to get the difference in day you'll need to divide the difference in milliseconds with (24 * 60 * 60 * 1000).

import java.util.Calendar;

public class DateDifferenceExample 
{    
    public static void main(String[] args)
    {
        // Creates two calendars instances
        Calendar cal1 = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
        
        // Set the date for both of the calendar instance
        cal1.set(2006, 12, 30);
        cal2.set(2007, 5, 3);

        // Get the represented date in milliseconds
        long milis1 = cal1.getTimeInMillis();
        long milis2 = cal2.getTimeInMillis();
        
        // Calculate difference in milliseconds
        long diff = milis2 - milis1;
        
        // Calculate difference in seconds
        long diffSeconds = diff / 1000;
        
        // Calculate difference in minutes
        long diffMinutes = diff / (60 * 1000);
        
        // Calculate difference in hours
        long diffHours = diff / (60 * 60 * 1000);
        
        // Calculate difference in days
        long diffDays = diff / (24 * 60 * 60 * 1000);
        
        System.out.println("In milliseconds: " + diff + " milliseconds.");
        System.out.println("In seconds: " + diffSeconds + " seconds.");
        System.out.println("In minutes: " + diffMinutes + " minutes.");
        System.out.println("In hours: " + diffHours + " hours.");
        System.out.println("In days: " + diffDays + " days.");
    }
}

Below is output....
In milliseconds: 10713600000 milliseconds.
In seconds: 10713600 seconds.
In minutes: 178560 minutes.
In hours: 2976 hours.
In days: 124 days.

How do I convert string to Date in GMT timezone in Android?


The following code snippet convert a string representation of a date into a java.util.Date object and the timezone is set to GMT. To parse the string so that the result is in GMT you must set theTimeZone of the DateFormat object into GMT.

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class WithTimezoneStringToDate {
    public static void main(String[] args) {
        //
        // Create a DateFormat and set the timezone to GMT.
        //
        DateFormat df = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z");
        df.setTimeZone(TimeZone.getTimeZone("GMT"));

        try {
            //
            // Convert string into Date
            //
            Date today = df.parse("Sun, 12 Feb 2012 00:00:00 GMT");
            System.out.println("Today = " + df.format(today));
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}

Below is the output.....

Today = Sun, 12 Feb 2012 00:00:00 GMT

How do I change the date format symbols for a specified locale in android?


import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class ChangeDateFormatSymbols {
    public static void main(String[] args) {
        Locale id = new Locale("in", "ID");
        String pattern = "EEEE, dd MMM yyyy";
        Date today = new Date();

        //
        // Gets formatted date specify by the given pattern for
        // Indonesian Locale no changes for default date format
        // is applied here.
        //
        SimpleDateFormat sdf = new SimpleDateFormat(pattern, id);
        String before = sdf.format(today);
        System.out.println("Before format change: " + before);

        //
        // Create a DateFormatSymbols object for Indonesian locale.
        //
        DateFormatSymbols dfs = new DateFormatSymbols(id);

        //
        // Gets String array of default format of weekdays.
        //
        String[] days = dfs.getWeekdays();
        String newDays[] = new String[days.length];
        for (int i = 0; i < days.length; i++) {
            //
            // For each day, apply toUpperCase() method to
            // capitalized it.
            //
            newDays[i] = days[i].toUpperCase();
        }

        //
        // Set String array of weekdays.
        //
        dfs.setWeekdays(newDays);

        //
        // Gets String array of default format of short months.
        //
        String[] shortMonths = dfs.getShortMonths();
        String months[] = new String[shortMonths.length];
        for (int j = 0; j < shortMonths.length; j++) {
            //
            // For each short month, apply toUpperCase() method
            // to capitalized it.
            //
            months[j] = shortMonths[j].toUpperCase();
        }

        //
        // Set String array of short months.
        //
        dfs.setShortMonths(months);

        //
        // Create a SimpleDateFormat object by given pattern and 
        // symbol and then format the date object as String.
        //
        sdf = new SimpleDateFormat(pattern, dfs);
        String after = sdf.format(today);
        System.out.println("After change format : " + after);
    }
}

Below is the output....

Before format change: Jumat, 10 Sep 2010
After change format : JUMAT, 10 SEP 2010