Here you can find the source of dateToString(Date date)
Parameter | Description |
---|---|
date | datum |
public static final String dateToString(Date date)
//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(); } }