Here you can find the source of format(Date dt)
Parameter | Description |
---|---|
dt | - Date |
Parameter | Description |
---|---|
Exception | an exception |
public static final String format(Date dt) throws Exception
//package com.java2s; /**// ww w .j a v a2s. co m * Copyright 2012 Subho Ghosh (subho dot ghosh at outlook dot com) * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final String _DEFAULT_DATE_FORMAT_ = "MM-dd-yyyy HH:mm:ss"; /** * Format the date using the default date format. * * @param dt * - Date * @return * @throws Exception */ public static final String format(Date dt) throws Exception { DateFormat formatter = new SimpleDateFormat(_DEFAULT_DATE_FORMAT_); return formatter.format(dt); } /** * Format the date using the specified date format. * * @param dt * - Date * @param format * - Date Format * @return * @throws Exception */ public static final String format(Date dt, String format) throws Exception { DateFormat formatter = new SimpleDateFormat(format); return formatter.format(dt); } }