Java Now formatTime(Date now, String pattern)

Here you can find the source of formatTime(Date now, String pattern)

Description

format Time

License

Apache License

Declaration

public static String formatTime(Date now, String pattern) 

Method Source Code

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

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

public class Main {
    public static String formatTime(Date now, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(now);
    }// w  ww  . j  a  va  2 s. c  o m

    public static String formatTime(Date now, String pattern, int tensMinutes) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmm");
        String timestamp = sdf.format(now);
        int len = timestamp.length();
        String dateHour = timestamp.substring(0, len - 2);
        int minute = Integer.valueOf(timestamp.substring(len - 2)) / tensMinutes * (tensMinutes / 10);
        return dateHour + minute + "0";
    }
}

Related

  1. formatNow()
  2. formatNow()
  3. formatNow(String fmt)
  4. formatNow(String pattern)
  5. formatNow(String style)
  6. getAllnowTime()
  7. getDisplayDateNow()
  8. getFormatNowDateTime(String formatStr)
  9. getFormattedDateNow(@Nonnull final String sFormat)