1

Log print dateStr -> 2019-07-05 12:05:36 currentDate -> Fri Jul 05 00:00:00 GMT+02:00 2019

I need -> Fri 05 Jul 2019 and also translated to Macedonian locale

String dateStr = obj.getString("sent_date");
            Log.d("date", dateStr);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            Date currentDate = null;
            try {
                currentDate = sdf.parse(dateStr);
                Log.d("date", currentDate.toString());

4 Answers4

0

If you want to use SimpleDateFormat with Macedonian local you can do like this:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", new Locale("mk", "MK"));

or you can use DateFormat instead in this way:

Date date = new Date(location.getTime());
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);
myDate = df.parse(dateStr);

for more formatting options you can look at docs

kAvEh
  • 534
  • 4
  • 15
0

If you are looking for the date format string,

SimpleDateFormat resultFormat = new SimpleDateFormat("E dd MMM yyyy", new Locale("mk", "MK"));
resultFormat.format(currentDate)

Should give you the expected result.

Maria
  • 369
  • 2
  • 7
0

Try this code:

  @SuppressLint("SimpleDateFormat")
    public static String formatTime(String dateFormat) {
        String inputTimePattern = "EEE MMM dd HH:mm:ss zzzz yyyy";
        String outputTimePattern = "yyyy-MM-dd HH:mm:ss";
        SimpleDateFormat inputFormat = new SimpleDateFormat(inputTimePattern, Locale.ENGLISH);
        SimpleDateFormat outputFormat = new SimpleDateFormat(outputTimePattern, new Locale("mk" ,""));
        Date date;
        try {
            date = inputFormat.parse(dateFormat);
            return outputFormat.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return dateFormat;
    }

    Log.d(TAG, formatTime("Fri Jul 05 00:00:00 GMT+02:00 2019"));

    Output -> 2019-07-05 00:00:00
Mahmoud Waked
  • 357
  • 2
  • 8
0

You can use this function just put your desire date format

private String returnData(String date) {
    SimpleDateFormat localDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    localDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    try {
        localDateFormat.parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    String finalDate = localDateFormat.format(new Date());
    return finalDate;
 }
pavel
  • 1,603
  • 22
  • 19