Android time format issue on different devices [duplicate] - java

This question already has answers here:
Time parsing issue on Android
(3 answers)
Closed 5 years ago.
String time1= "12:45 PM"; Device1 default format ,
String time2= "12:45 p.m."; Device2 default format
These two times are same but looks different format in different devices. Testing with remi note4 (time1 format) and Samsung j7 (time2 format).
If I'm using device with default time format 'time1' then i cant convert string format 'time2' to timestamp. Logger shows unable parse date . How to resolve this problem?
NB: Time to be converted is fetching from server as JSON string format.

You can first convert it to same format then you will parse like :
String time1= "12:45 PM";
String time2= "12:45 p.m.";
String modify_time_2 = time2.replace("p.m.","PM").replace("pm","PM").replace("p m","PM");
You can use this modify_time_2 for converting it to time.

Another question of mine got the exact answer for the following issue. Please refer following link if anyone wants to know..Refer following link

Related

Android : how to get now date time string in following format "2015-10-08T08:09:22.067+00:00"?

I would like to ask how can i get string with 'now' date in the following format?
"2015-10-08T08:09:22.067+00:00" ?
Many thanks for any advice.
Have a look here at the simpledateformat method:
http://developer.android.com/reference/java/text/SimpleDateFormat.html
I think you should use the simple date format to format your date string . For this, consider reading the this link .
But if you want just to change the string and get the time then just follow this link or this link
I hope this answer would help you.

Android Number Format Output?

i'm learn Java thourgh Android Studio with Java, i was stuck at the Float Format, how can you display, for example: 1.234E10 instead of 12340000000000, thanks guys
12340000000000 is actually 1.234E13
DecimalFormat formatter = new DecimalFormat("0.###E0");
String format = formatter.format(12340000000000.0);
System.out.println(format);
Output:
1.234E13
1.234E10 is actually the same as 12340000000000 only it's printed out in an engineering format and it's a hell of a lot more readable than 12340000000000.

convert Time "HH:mm:ss.000Z" from Time "HH:mm:ss"

I am developing one Java application and getting data from webservice with parameter Time "HH:mm:ss.000Z" format.
How do I convert Time "HH:mm:ss.000Z" from Time "HH:mm:ss" format using below line but getting same error for time.
There is auto generated code from wsdl.
org.apache.axis.types.Time time=new org.apache.axis.types.Time("00:00:01");
Check implementation of class Time.
private static SimpleDateFormat zulu =
new SimpleDateFormat("HH:mm:ss.SSS'Z'");
This is SimpleDateFormat used by Time class to convert time to that format.

Date format in JavaScript and Java

I have these time formats in Java which I use to format the date:
dd-mm-yyyy
dd-mm-rr
dd-mon-yyyy
dd-mon-rr
dd/mon/yyyy
When I use these time formats with JQuery time picker I get this output:
24-08-rr
24-08-20122012
Can you tell me how I can use one time format for Java and for JavaScript? How I can solve this problem?
For example you can use next:
-On client side
$("#input-field-id").datepicker().mask("99/99/9999");
-On server side
org.joda.time.format.DateTimeFormatter DATE_TIME_FORMATTER =
DateTimeFormat.forPattern("MM/dd/yyyy");
DATE_TIME_FORMATTER.parseDateTime(dateThatYouGatFromClientPart);
You can use latest version of jQuery UI datepicker which has the following useful functions
http://docs.jquery.com/UI/Datepicker/formatDate
http://docs.jquery.com/UI/Datepicker/parseDate

Custom date format in android for given locale

I'm trying to format a date for a given locale new Locale("mk", "MK"). The locale is valid, it returns the country name and language properly. I want to use custom string, in my case "E, kk:mm" or "EEEE, kk:mm". I want the output to be "сабота, 12:00", but what I get is "7, 12:00".
This is how I use it and I tried many ways, but they all seem to behave the same.
SimpleDateFormat sdf = new SimpleDateFormat("EEEE, kk:mm", new Locale("mk", "MK));
sdf.format(new Date());
// output: 7, 12:30
Another method I tried
Calendar calendar = Calendar.getInstance(new Locale("mk", "MK"));
calendar.setTimeInMillis(new Date().getTime());
DateFormat.format("EEEE, kk:mm", calendar);
// output: Saturday, 12:30
I also tried using java.text.DateFormat instead android class, but no change.
The phone locale is set to English, but this is localized app, I want to show dates in a fixed locale format.
I've looked into many SO question regarding this issue and I wasn't able to find answer. I'm not interested in predefined formats, I want to use my own format and I want the date/month names to be formatted for the input locale.
I think the problem is that Macedonia is not a supported locale on the Android JVM. If you run your code as plain Java console app, it's fine. The method Locale.getAvailableLocales() returns 152 members in plain Java, only 88 in an Android emulator. If you have the code snippet:
Locale[] locales = Locale.getAvailableLocales();
String cCode;
for (Locale loc :locales){
cCode = loc.getCountry();
if (cCode.equalsIgnoreCase("MK"))
Toast.makeText(this, cCode, Toast.LENGTH_SHORT).show();
// Or System.out.println() in a Java app
}
Then the toast doesn't show for "MK" although it will println in the Java app
From documentation of SimpleDateFormat:
**Text**: For formatting, if the number of pattern letters is 4 or more,
the full form is used; otherwise a short or abbreviated form is used if
available. For parsing, both forms are accepted, independent of the
number of pattern letters.
So this should fix it:
SimpleDateFormat sdf = new SimpleDateFormat("EEEE, kk:mm", new Locale("mk", "MK"));
NickT was faster :-), so just adding to his answer: if you want to see your locales supported on Android, run:
for (Locale l:Locale.getAvailableLocales()) {
Log.d(l.getDisplayCountry(),l.toString());
}
and you will see that Macedonia is not on the list.

Categories

Resources