Java Today todayStr()

Here you can find the source of todayStr()

Description

today Str

License

Apache License

Declaration

public static String todayStr() 

Method Source Code

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

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static final String DEFAULT_FORMAT_DATE = "yyyy-MM-dd";

    public static String todayStr() {
        return currentDateStr();
    }/*from  ww w.  j  a  v  a 2s  .  c o  m*/

    public static String currentDateStr() {
        return toDateString(new Date(), DEFAULT_FORMAT_DATE);
    }

    public static String toDateString(Date date, String format) {
        SimpleDateFormat sf = new SimpleDateFormat(format);
        return sf.format(date);
    }

    public static String format(String text, Date date) {
        int start = text.indexOf("{");
        int end = text.indexOf("}");
        while (start > 0 && end > 0) {
            String subStr = text.substring(start, end + 1);
            String format = text.substring(start + 1, end);
            String dateStr = toDateString(date, format);
            text = text.replace(subStr, dateStr);

            start = text.indexOf("{");
            end = text.indexOf("}");
        }
        return text;
    }
}

Related

  1. toDaysBeforeOrAfter(Date date, Integer days)
  2. todaysDate(int style)
  3. todaySortedTimestamp()
  4. todayStart()
  5. todaysTime()
  6. todayString(final String sFormat)
  7. translateToDayNumber(int y, int m, int d)