Example usage for java.text DateFormat getDateInstance

List of usage examples for java.text DateFormat getDateInstance

Introduction

In this page you can find the example usage for java.text DateFormat getDateInstance.

Prototype

public static final DateFormat getDateInstance(int style, Locale aLocale) 

Source Link

Document

Gets the date formatter with the given formatting style for the given locale.

Usage

From source file:org.libreplan.web.orders.DynamicDatebox.java

public DynamicDatebox(Getter<Date> getter, Setter<Date> setter) {
    this.setter = setter;
    this.getter = getter;
    this.dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locales.getCurrent());
}

From source file:io.lightlink.excel.StreamingExcelExporter.java

/**
 * Override to redefine datetime format (second line of the exported document). Default value is "dd/MM/yyyy HH:mm"
 *
 * @return//  w ww. j a  v a2 s  .c  om
 */
protected DateFormat getExportDateTimeFormat() {
    String dateFormat = (String) data.get("dateFormat"); // todo getDate from typesFacade
    if (dateFormat == null) {
        return DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault());
    } else
        return new SimpleDateFormat(dateFormat);
}

From source file:org.openmrs.web.dwr.DrugOrderListItem.java

public DrugOrderListItem(DrugOrder drugOrder) {
    orderId = drugOrder.getOrderId();/*from www  . jav a  2 s .c  om*/
    if (drugOrder.getConcept() != null) {
        conceptId = drugOrder.getConcept().getConceptId();
        conceptName = drugOrder.getConcept().getName().getName();
    }
    instructions = drugOrder.getInstructions();

    DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, Context.getLocale());

    if (drugOrder.getStartDate() != null)
        startDate = df.format(drugOrder.getStartDate());
    if (drugOrder.getAutoExpireDate() != null)
        autoExpireDate = df.format(drugOrder.getAutoExpireDate());
    if (drugOrder.getEncounter() != null)
        encounterId = drugOrder.getEncounter().getEncounterId();
    if (drugOrder.getOrderer() != null)
        ordererId = drugOrder.getOrderer().getProviderId();
    discontinued = drugOrder.getDiscontinued();
    if (drugOrder.getDiscontinuedBy() != null)
        discontinuerId = drugOrder.getDiscontinuedBy().getUserId();
    if (drugOrder.getDiscontinuedDate() != null)
        discontinuedDate = df.format(drugOrder.getDiscontinuedDate());
    if (drugOrder.getDiscontinuedReason() != null)
        discontinueReason = drugOrder.getDiscontinuedReason();
    if (drugOrder.getDrug() != null)
        drugId = drugOrder.getDrug().getDrugId();
    if (drugOrder.getDrug() != null)
        drugName = drugOrder.getDrug().getName();
    dose = drugOrder.getDose();
    doseUnits = drugOrder.getDoseUnits();
    frequency = drugOrder.getFrequency();
    asNeeded = drugOrder.getAsNeeded();
    quantity = drugOrder.getQuantity();
    voided = drugOrder.getVoided();
    if (drugOrder.getVoidedBy() != null)
        voiderId = drugOrder.getVoidedBy().getUserId();
    if (drugOrder.getDateVoided() != null)
        voidedDate = df.format(drugOrder.getDateVoided());
    voidReason = drugOrder.getVoidReason();
    if (drugOrder.getCreator() != null)
        creatorId = drugOrder.getCreator().getUserId();
    if (drugOrder.getDateCreated() != null)
        createdDate = df.format(drugOrder.getDateCreated());
}

From source file:ispok.converter.BirthDateConverter.java

@Override
public String getAsString(FacesContext fc, UIComponent uic, Object o) {

    Locale locale = fc.getViewRoot().getLocale();
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);

    SimpleDateFormat sdf = (SimpleDateFormat) df;
    String pattern = sdf.toPattern();

    pattern = pattern.replace("yy", "yyyy");

    Date date = (Date) o;/* w  ww  .  ja  va 2s . com*/

    sdf.applyPattern(pattern);

    return sdf.format(date);
}

From source file:com.appeaser.sublimepicker.SublimePickerFragment.java

public SublimePickerFragment() {
    // Initialize formatters
    mDateFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault());
    mTimeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault());
    mTimeFormatter.setTimeZone(TimeZone.getTimeZone("GMT+0"));
}

From source file:org.linesofcode.alltrack.graph.AddValueActivity.java

private void initializeContent() {
    calendar = Calendar.getInstance();
    dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
    timeFormat = new SimpleDateFormat(TIME_PATTERN, Locale.getDefault());

    dateView = (TextView) findViewById(R.id.add_value_date);
    timeView = (TextView) findViewById(R.id.add_value_time);

    Button okButton = (Button) findViewById(R.id.add_value_ok);
    okButton.setOnClickListener(new View.OnClickListener() {
        @Override//from  w ww  .j a v  a  2 s  . com
        public void onClick(View v) {
            addValue();
        }
    });

    Button cancelButton = (Button) findViewById(R.id.add_value_cancel);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setResult(Activity.RESULT_CANCELED, new Intent(ADD_VALUE_ACTION_CODE));
            finish();
        }
    });

    EditText value = (EditText) findViewById(R.id.add_value_value);
    value.setOnKeyListener(new View.OnKeyListener() {

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_ENTER:
                    addValue();
                    return true;
                }
            }
            return false;
        }
    });

    dateView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDatePicker();
        }
    });

    timeView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showTimePicker();
        }
    });

    updateDateTimeFields();

    Bundle extras = getIntent().getExtras();
    graphId = extras.getInt("graphId");
    position = extras.getInt("position");
    Log.d(TAG, "Starting addValue Activity for graph [" + graphId + "] in position [" + position + "].");
    graph = graphService.getById(graphId);
}

From source file:org.idansof.otp.client.Planner.java

public PlanResult generatePlan(PlanRequest planRequest)
        throws IOException, XmlPullParserException, ParseException {

    AndroidHttpClient androidHttpClient = AndroidHttpClient.newInstance("");
    try {//from w  w  w.j a va  2s. co m

        DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale);
        DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, locale);

        Uri.Builder builder = Uri.parse("http://" + host).buildUpon();

        builder.appendEncodedPath(uri);
        builder.appendQueryParameter("fromPlace", planRequest.getFrom().getCoordinateString());
        builder.appendQueryParameter("toPlace", planRequest.getTo().getCoordinateString());
        builder.appendQueryParameter("date", dateFormat.format(planRequest.getDate()));
        builder.appendQueryParameter("time", timeFormat.format(planRequest.getDate()));

        HttpProtocolParams.setContentCharset(androidHttpClient.getParams(), "utf-8");
        String uri = builder.build().toString();
        Log.i(Planner.class.toString(), "Fetching plan from " + uri);
        HttpUriRequest httpUriRequest = new HttpGet(uri);
        httpUriRequest.setHeader("Accept", "text/xml");
        HttpResponse httpResponse = androidHttpClient.execute(httpUriRequest);

        InputStream contentStream = httpResponse.getEntity().getContent();
        Log.i(Planner.class.toString(),
                "Parsing content , size :" + httpResponse.getEntity().getContentLength());
        return parseXMLResponse(contentStream);
    } finally {
        androidHttpClient.close();
    }
}

From source file:org.openmrs.reporting.DrugOrderFilter.java

public String getDescription() {
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Context.getLocale());
    StringBuffer ret = new StringBuffer();
    boolean currentlyCase = getWithinLastDays() != null && getWithinLastDays() == 0
            && (getWithinLastMonths() == null || getWithinLastMonths() == 0);
    if (currentlyCase)
        ret.append("Patients currently ");
    else//  ww w.  j a v  a2 s .co m
        ret.append("Patients ");
    if (getDrugListToUse() == null || getDrugListToUse().size() == 0) {
        if (getAnyOrAll() == GroupMethod.NONE)
            ret.append(currentlyCase ? "taking no drugs" : "who never took any drugs");
        else
            ret.append(currentlyCase ? "taking any drugs" : "ever taking any drugs");
    } else {
        if (getDrugListToUse().size() == 1) {
            if (getAnyOrAll() == GroupMethod.NONE)
                ret.append("not taking ");
            else
                ret.append("taking ");
            ret.append(getDrugListToUse().get(0).getName());
        } else {
            ret.append("taking " + getAnyOrAll() + " of [");
            for (Iterator<Drug> i = getDrugListToUse().iterator(); i.hasNext();) {
                ret.append(i.next().getName());
                if (i.hasNext())
                    ret.append(" , ");
            }
            ret.append("]");
        }
    }
    if (!currentlyCase)
        if (getWithinLastDays() != null || getWithinLastMonths() != null) {
            ret.append(" withing the last");
            if (getWithinLastMonths() != null)
                ret.append(" " + getWithinLastMonths() + " months");
            if (getWithinLastDays() != null)
                ret.append(" " + getWithinLastDays() + " days");
        }
    if (getSinceDate() != null)
        ret.append(" since " + df.format(getSinceDate()));
    if (getUntilDate() != null)
        ret.append(" until " + df.format(getUntilDate()));
    return ret.toString();
}

From source file:com.jslsolucoes.tagria.lib.util.TagUtil.java

public static String format(String type, String value, JspContext jspContext) {

    if (StringUtils.isEmpty(value)) {
        return value;
    } else if ("date".equals(type) || "timestamp".equals(type) || "hour".equals(type)) {

        DateFormat dateFormat = DateFormat.getDateTimeInstance();
        if ("timestamp".equals(type)) {
            dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM,
                    locale(jspContext));
        } else if ("date".equals(type)) {
            dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale(jspContext));
        } else if ("hour".equals(type)) {
            dateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale(jspContext));
        }//from  w w w .j  ava2 s.com
        List<String> patterns = new ArrayList<>();
        patterns.add("yyyy-MM-dd HH:mm:ss");
        patterns.add("yyyy-MM-dd");
        patterns.add("E MMM dd HH:mm:ss zzz yyyy");
        for (String pattern : patterns) {
            try {
                return dateFormat.format(new SimpleDateFormat(pattern, Locale.ENGLISH).parse(value));
            } catch (ParseException pe) {
                //Try another format
            }
        }
        return value;
    } else if ("currency".equals(type)) {
        DecimalFormat nf = new DecimalFormat("#,##0.00", new DecimalFormatSymbols(locale(jspContext)));
        return nf.format(new Double(value));
    } else if ("cep".equals(type)) {
        return String.format("%08d", Long.valueOf(value)).replaceAll("^([0-9]{5})([0-9]{3})$", "$1-$2");
    } else if ("cpf".equals(type)) {
        return String.format("%011d", Long.valueOf(value))
                .replaceAll("^([0-9]{3})([0-9]{3})([0-9]{3})([0-9]{2})$", "$1.$2.$3-$4");
    } else if ("cnpj".equals(type)) {
        return String.format("%014d", Long.valueOf(value))
                .replaceAll("^([0-9]{2})([0-9]{3})([0-9]{3})([0-9]{4})([0-9]{2})$", "$1.$2.$3/$4-$5");
    } else if ("tel".equals(type)) {
        return String.format("%010d", Long.valueOf(value)).replaceAll("^([0-9]{2})([0-9]{4,5})([0-9]{4})$",
                "($1) $2-$3");
    }
    return value;
}

From source file:com.flexive.war.JsonWriter.java

public JsonWriter(Writer out, Locale locale) {
    this.out = out;
    this.dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
}