From: Marius Gavrilescu Date: Wed, 21 Aug 2013 12:29:54 +0000 (+0300) Subject: Better date/time formatting X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=f6f4503f1766940d2e29c4605b2dc0eebc2765e9;p=unical.git Better date/time formatting --- diff --git a/src/ro/ieval/unical/DisplayEventActivity.java b/src/ro/ieval/unical/DisplayEventActivity.java index 0bff032..4f16069 100644 --- a/src/ro/ieval/unical/DisplayEventActivity.java +++ b/src/ro/ieval/unical/DisplayEventActivity.java @@ -1,5 +1,6 @@ package ro.ieval.unical; +import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; @@ -45,7 +46,7 @@ public class DisplayEventActivity extends Activity { final TextView date = (TextView) rowView.findViewById(R.id.alarm_datetime); final Button delete = (Button) rowView.findViewById(R.id.alarm_delete); delete.setOnClickListener(new DeleteListener(getItem(position))); - date.setText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.UK).format(getItem(position))); + date.setText(DateFormat.getDateTimeInstance().format(getItem(position))); return rowView; } @@ -75,9 +76,9 @@ public class DisplayEventActivity extends Activity { final Date start=new Date(event.dtstart); final Date end=new Date(event.dtend); - final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.UK); - final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss", Locale.UK); - final SimpleDateFormat dayOfWeekFormat = new SimpleDateFormat("EEEEEEE", Locale.UK); + final DateFormat dateFormat = DateFormat.getDateInstance(); + final DateFormat timeFormat = DateFormat.getTimeInstance(); + final DateFormat dayOfWeekFormat = new SimpleDateFormat("EEEEEEE", Locale.UK); startDay.setText(dayOfWeekFormat.format(start)); if(!dateFormat.format(start).equals(dateFormat.format(end))) { diff --git a/src/ro/ieval/unical/EventListActivity.java b/src/ro/ieval/unical/EventListActivity.java index 3461781..41b3cd7 100644 --- a/src/ro/ieval/unical/EventListActivity.java +++ b/src/ro/ieval/unical/EventListActivity.java @@ -15,6 +15,7 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; +import java.text.DateFormat; import java.util.Arrays; import java.util.Comparator; import java.util.Date; @@ -45,10 +46,11 @@ public final class EventListActivity extends ListActivity { final TextView dstart = (TextView) rowView.findViewById(R.id.smalldatestart); final TextView dend = (TextView) rowView.findViewById(R.id.smalldateend); final View header = rowView.findViewById(R.id.rowHeader); + final DateFormat format = DateFormat.getDateTimeInstance(); header.setBackgroundColor(events[position].eventColour); title.setText(events[position].title); - dstart.setText(new Date(events[position].dtstart).toString()); - dend.setText(new Date(events[position].dtend).toString()); + dstart.setText(format.format(new Date(events[position].dtstart))); + dend.setText(format.format(new Date(events[position].dtend))); return rowView; }