Java Date Convert dateToString(Date date)

Here you can find the source of dateToString(Date date)

Description

Pretvara datum u tekst, i to samo dan (format "yyyy-MM-dd").

License

Apache License

Parameter

Parameter Description
date datum

Return

tekst koji predstavlja taj datum

Declaration

public static final String dateToString(Date date) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**//w  ww .j av  a2 s .c om
     * Pretvara datum u tekst, i to samo dan (format "yyyy-MM-dd").
     * 
     * @param date datum
     * @return tekst koji predstavlja taj datum
     */
    public static final String dateToString(Date date) {
        if (date == null)
            return "";
        StringBuilder sb = new StringBuilder(10);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);

        int day = cal.get(Calendar.DAY_OF_MONTH);
        int month = cal.get(Calendar.MONTH) - Calendar.JANUARY + 1;
        int year = cal.get(Calendar.YEAR);

        sb.append(year).append('-');
        if (month < 10)
            sb.append('0');
        sb.append(month).append('-');
        if (day < 10)
            sb.append('0');
        sb.append(day);
        return sb.toString();
    }
}

Related

  1. dateToQTime(final Date date)
  2. dateToRRNDate(Date date)
  3. DateToStr(java.util.Date val)
  4. dateToString(Date date)
  5. dateToString(Date date)
  6. dateToString(final Date date)
  7. dateToUnixTimestamp(Date date)
  8. dateToUTC(Date d)
  9. dateToXdsDateString(Date date, int format)