Here you can find the source of format(final Date date)
Parameter | Description |
---|---|
date | The date to format. |
public static String format(final Date date)
//package com.java2s; /******************************************************************************* * Copyright 2010-2016 CNES - CENTRE NATIONAL d'ETUDES SPATIALES * * This file is part of SITools2.//from w ww . jav a2 s .co m * * SITools2 is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SITools2 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with SITools2. If not, see <http://www.gnu.org/licenses/>. ******************************************************************************/ import java.util.Date; public class Main { /** * Default date format for date exchange between the server and the client in all the Sitools2 application */ public static final String SITOOLS_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS"; /** * Formats a Date according to the default date format. * * @param date * The date to format. * @return The formatted date. */ public static String format(final Date date) { return format(date, SITOOLS_DATE_FORMAT); } /** * Formats a Date according to the first format in the array. * * @param date * The date to format. * @param format * The date format to use. * @return The formatted date. */ public static String format(final Date date, final String format) { if (date == null) { throw new IllegalArgumentException("Date is null"); } java.text.DateFormat formatter = null; formatter = new java.text.SimpleDateFormat(format, java.util.Locale.ROOT); return formatter.format(date); } }