Here you can find the source of format(Date d)
Parameter | Description |
---|---|
d | the date |
public static String format(Date d)
//package com.java2s; /*//from w w w. j ava2 s.c o m * Copyright 2015 Adaptris Ltd. * * 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.SimpleDateFormat; import java.util.Date; public class Main { private static final String[] DATE_FORMATS = { "yyyy-MM-dd'T'HH:mm:ssZ", "yyyyMMdd HH:mm:ss zzz", "yyyyMMdd HH:mm:ss", "yyyyMMdd", "yyyy-MM-dd HH:mm:ss zzz", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd", "dd.MM.yyyy HH:mm:ss zzz", "dd.MM.yyyy HH:mm:ss", "dd.MM.yyyy", "dd/MM/yyyy HH:mm:ss zzz", "dd/MM/yyyy HH:mm:ss", "dd/MM/yyyy HH:mm:ss", "dd/MM/yyyy", }; /** * Return the default formatted String for a given date. * * @param d the date * @return the formatted string yyyy-MM-dd'T'HH:mm:ssZ */ public static String format(Date d) { String format = DATE_FORMATS[0]; SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.format(d); } }