Calendar returning birmanian numbers - android

something strange happened. I'm using Calendar to name the audiofiles I'm recording. Everything was working ok until today. The next code is giving me the date in birmanian, I don't know why.
The code is simple:
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 1);
SimpleDateFormat format1 = new SimpleDateFormat("HH;mm;ss[,[dd-MM-yyyy");
String formatted = format1.format(cal.getTime());
(I'm using all the "; , [ and more strange characters to create the file after, it is not the cause of the problem it worked well few days ago)
what I'm getting is:
formatted = ၁၃;၅၃;၂၅[,[၃၁-၀၅-၂၀၁၆
Any help?
Thanks for your time!

Related

TimePickerDialog doesn't show properly in Android 6

i'm using DatePickerDialog to select time on my app. When I run my app on a device with Android 5 as OS the dialog shows properly, meanwhile if i run my app on a device with Android 6 this is what the dialog looks like:
Could someone help me?
I solved the issue changing the way that the TimePickerDialog was being created.
I had this code :
Calendar c = Calendar.getInstance();
return new TimePickerDialog(getContext(), myTimeListener, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true);
I changed the 2nd line for this one:
Calendar c = Calendar.getInstance();
return new TimePickerDialog(getContext(), R.style.AppTheme, myTimeListener, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true);

How to set day of weeks for email reminder of Google Calendar Event object by java code?

I want to set repeat email notification in Google calendar API v3. I create nofication:
EventReminder reminder = new EventReminder();
reminder.setMinutes(5);
reminder.setMethod("email");
Event.Reminders eRem = new Event.Reminders();
List<EventReminder> reminders = new ArrayList<>();
reminders.add(reminder);
eRem.setOverrides(reminders);
eRem.setUseDefault(false);
event.setReminders(eRem);
It`s work fine, but I cant find solution to set repeat days for this notification. Have any idea?
The API only offers the EventReminder.setMinutes() method, but you could use TimeUnit to convert your number of days in minutes like so:
// Reminder in 2 days
reminder.setMinutes(TimeUnit.MINUTES.convert(2, TimeUnit.DAYS));

Java/Android Calendar, add 1 week on Sundays

OK, so my code has worked good until the day became Sunday.
I'm working on an app that uses the Calendar util allot, so it functioning the way i think it does is important to me! The problem:
import java.util.Calendar;
...
Calendar test = Calendar.getInstance();
test.setFirstDayOfWeek(Calendar.MONDAY);
Log.e("WEEEK TEST:", ""+ test.get(Calendar.WEEK_OF_YEAR));
test.add(Calendar.WEEK_OF_YEAR, 1);
Log.e("WEEEK TEST:", ""+ test.get(Calendar.WEEK_OF_YEAR));
Outputs this:
06-01 14:04:07.636 12005-12005/test.app E/WEEEK TEST:﹕ 23
06-01 14:04:07.636 12005-12005/test.app E/WEEEK TEST:﹕ 23
How can this even happen, and how do i fix it?
Calendar test = Calendar.getInstance();
test.add(Calendar.WEEK_OF_YEAR, -1);
test.add(Calendar.WEEK_OF_YEAR, 1);
test.setFirstDayOfWeek(Calendar.MONDAY);
Now "test" should work correctly

Android:Changing time format as per the Device's Current time format

How to get current time format of the android device? i.e. If the android device's current time format is changed from 12hr to 24 hr format and vice versa, then how to check that setting programatically?
I want to change the time shown in my app widget to be of same format as the device's and whenever the time format is changed then my widget should also show that time format. Any pointers will be helpful.
thanks.
You can use TIME_12_24.
int time_format = 0;
try {
time_format = Settings.System.getInt(getContentResolver(), Settings.System.TIME_12_24);
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
Log.i(TAG,"Time format: "+time_format);
time_format will have 12 or 24 based on the settings.
Make sure you have added this permission to manifiest file.
<user-permission android:name="android.permission.WRITE_SETTINGS" />
EDIT :
You can also use DateFormat.is24HourFormat(). It doesn't require an extra permission.
The simple way would be to use to use android native android.text.format.DateFormat class's is24HourFormat(this) static method as below.
if (android.text.format.DateFormat.is24HourFormat(YourActivityName.this)) {
// 24 hour format
}
else
{
// 12 hour format
}
check, http://developer.android.com/reference/android/text/format/DateFormat.html
DateFormat::getDateFormat()
Date date = new Date(location.getTime());
dateFormat.format(date);
Please check this...
http://developer.android.com/reference/java/text/SimpleDateFormat.html
How do you format date and time in Android?
24 hour clock not working in dateformat android

String.format doesn't give month and weeknames in German locale

I'm using following code in my app:
Calendar tmpCalendar = Calendar.getInstance(Locale.getDefault());
String itemTime = String.format(
Locale.getDefault(),
"%1$tA, %1$te. %1$tB %1$tY",
tmpCalendar);
German is the default language on my device, so I'd expect to get something like:
Dienstag, 7. Juni 2011
Instead I'm getting:
3, 7. 6 2011
If I use Locale.US instead of Locale.getDefault() everything works fine. Am I doing something wrong?
Oddly, it works in an emulator running Android 2.2 in German, but not on a HTC Desire, also running 2.2. Why?
It seems to be a bug of some vendors and is issue #9453 in the Android issue tracker.
SimpleDateFormat sdf = new SimpleDateFormat("EE/MM/yyyy");
Date date = new Date();
String sDate= sdf.format(date);
Read more on it here
It does exactly what you ask it to do. If you want to have fine-grain control over the process, you can always use SimpleDateFormat. However, I would rather recommend this method:
Calendar tmpCalendar = Calendar.getInstance(Locale.getDefault());
DateFormat formatter = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
formatter.setTimeZone(TimeZone.getDefault());
String itemTime = formatter.format(tmpCalendar.getTime());
Also, I would recommend using DateFormat.DEFAULT but you expect long date format, so...

Categories

Resources