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

Displaying AM and PM in lower case after date formatting

This works public class Timeis { public static void main(String s[]) { long ts = 1022895271767L; SimpleDateFormat sdf = new SimpleDateFormat(” MMM d ‘at’ hh:mm a”); // CREATE DateFormatSymbols WITH ALL SYMBOLS FROM (DEFAULT) Locale DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault()); // OVERRIDE SOME symbols WHILE RETAINING OTHERS symbols.setAmPmStrings(new String[] { “am”, “pm” }); sdf.setDateFormatSymbols(symbols); String … Read more

Generic support for ISO 8601 format in Java 6

Seems that you can use this: import java.util.Calendar; import javax.xml.bind.DatatypeConverter; public class TestISO8601 { public static void main(String[] args) { parse(“2012-10-01T19:30:00+02:00”); // UTC+2 parse(“2012-10-01T19:30:00Z”); // UTC parse(“2012-10-01T19:30:00”); // Local } public static Date parse(final String str) { Calendar c = DatatypeConverter.parseDateTime(str); System.out.println(str + “\t” + (c.getTime().getTime()/1000)); return c.getTime(); } }

SimpleDateFormat returns wrong time zone during parse

tl;dr i need to make a Date Object from String input but the time zone should remain UTC. LocalDate.parse( “23.01.2017” , DateTimeFormatter.ofPattern( “dd.MM.uuuu” ) ) …and… LocalTime.parse( “12:34:56” ) …combine… OffsetDateTime.of( datePart , timePart , ZoneOffset.UTC ) Details You are using troublesome confusing old date-time classes that are now supplanted by the java.time classes. OffsetDateTime … Read more

Java Convert GMT/UTC to Local time doesn’t work as expected

I also recommend using Joda as mentioned before. Solving your problem using standard Java Date objects only can be done as follows: // **** YOUR CODE **** BEGIN **** long ts = System.currentTimeMillis(); Date localTime = new Date(ts); String format = “yyyy/MM/dd HH:mm:ss”; SimpleDateFormat sdf = new SimpleDateFormat(format); // Convert Local Time to UTC (Works … Read more

SimpleDateFormat parse(string str) doesn’t throw an exception when str = 2011/12/12aaaaaaaaa?

The JavaDoc on parse(…) states the following: parsing does not necessarily use all characters up to the end of the string It seems like you can’t make SimpleDateFormat throw an exception, but you can do the following: SimpleDateFormat sdf = new SimpleDateFormat(“yyyy/MM/d”); sdf.setLenient(false); ParsePosition p = new ParsePosition( 0 ); String t1 = “2011/12/12aaa”; System.out.println(sdf.parse(t1,p)); … Read more