Here you can find the source of toStr2(Date now)
public static String toStr2(Date now)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static SimpleDateFormat dateFomat2 = new SimpleDateFormat("yyyyMMdd"); public static String toStr2(Date now) { String s = ""; try {/* ww w . j av a 2s . co m*/ s = dateFomat2.format(now); } catch (Exception e) { e.printStackTrace(); } return s; } }