Android Calendar String Parse format(String time)

Here you can find the source of format(String time)

Description

format "yyyy-MM-dd HH:mm:ss"

Declaration

public static String format(String time) 

Method Source Code

//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

public class Main {
    private static SimpleDateFormat parser = new SimpleDateFormat(
            "yyyy-MM-dd HH:mm:ss", Locale.getDefault());
    private static SimpleDateFormat formatter = new SimpleDateFormat(
            "dd-MM-yyyy HH:mm", Locale.getDefault());

    public static String format(String time) {
        try {//from  w  w w  .  jav  a  2 s.c  om
            // Fix for the database timezone to Brazilian timezone.
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(parser.parse(time));
            calendar.add(Calendar.HOUR, 3);

            return formatter.format(calendar.getTime())
                    .replaceAll("-", "/");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }
}

Related

  1. fromString(String dateString, String format)
  2. parseCalendar(int year, int month, double day, TimeZone zone)
  3. parseCalendar(int year, int month, int day, int hour, int minute, int second, int millisecond, TimeZone zone)
  4. parseDA(Calendar c, String s, int off, int len)