Converting date-string to a different format

Use java.util.DateFormat: DateFormat fromFormat = new SimpleDateFormat(“yyyy-MM-dd”); fromFormat.setLenient(false); DateFormat toFormat = new SimpleDateFormat(“dd-MM-yyyy”); toFormat.setLenient(false); String dateStr = “2011-07-09”; Date date = fromFormat.parse(dateStr); System.out.println(toFormat.format(date));

Get current time in a given timezone : android

I got it to work like this : TimeZone tz = TimeZone.getTimeZone(“GMT+05:30”); Calendar c = Calendar.getInstance(tz); String time = String.format(“%02d” , c.get(Calendar.HOUR_OF_DAY))+”:”+ String.format(“%02d” , c.get(Calendar.MINUTE))+”:”+ . String.format(“%02d” , c.get(Calendar.SECOND))+”:”+ . String.format(“%03d” , c.get(Calendar.MILLISECOND)); Also, every other time conversion based on this date should also be used with this timezone, otherwise, the default timezone of device … Read more

How can I get current date in Android?

You can use the SimpleDateFormat class for formatting date in your desired format. Just check this link where you get an idea for your example. For example: String dateStr = “04/05/2010”; SimpleDateFormat curFormater = new SimpleDateFormat(“dd/MM/yyyy”); Date dateObj = curFormater.parse(dateStr); SimpleDateFormat postFormater = new SimpleDateFormat(“MMMM dd, yyyy”); String newDateStr = postFormater.format(dateObj); Update: The detailed example … Read more

Display the current time and date in an Android application

Okay, not that hard as there are several methods to do this. I assume you want to put the current date & time into a TextView. String currentDateTimeString = java.text.DateFormat.getDateTimeInstance().format(new Date()); // textView is the TextView view that should display it textView.setText(currentDateTimeString); There is more to read in the documentation that can easily be found … Read more

how to convert milliseconds to date format in android?

Just Try this Sample code:- import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; public class Test { /** * Main Method */ public static void main(String[] args) { System.out.println(getDate(82233213123L, “dd/MM/yyyy hh:mm:ss.SSS”)); } /** * Return date in specified format. * @param milliSeconds Date in milliseconds * @param dateFormat Date format * @return String representing date in specified … Read more