Here you can find the source of convertDateToDateString(Date date)
Parameter | Description |
---|---|
date | Instance of java.util.Date. |
public static String convertDateToDateString(Date date)
//package com.java2s; /* The contents of this file are subject to the license and copyright terms * detailed in the license directory at the root of the source tree (also * available online at http://fedora-commons.org/license/). *///from w ww .j a v a 2 s. co m import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { /** * Converts an instance of java.util.Date into a String using the date * format: yyyy-MM-ddZ. * * @param date * Instance of java.util.Date. * @return Corresponding date string (returns null if Date argument is * null). */ public static String convertDateToDateString(Date date) { if (date == null) { return null; } else { DateFormat df = new SimpleDateFormat("yyyy-MM-dd'Z'"); df.setTimeZone(TimeZone.getTimeZone("UTC")); return df.format(date); } } }