Java Date Create toDateFormat(Date date)

Here you can find the source of toDateFormat(Date date)

Description

Returns a string in standard PDF date format representing the specified date (in the default timezone).

License

Open Source License

Parameter

Parameter Description
date the date ( null not permitted).

Return

A string in standard PDF date format.

Declaration

public static String toDateFormat(Date date) 

Method Source Code

//package com.java2s;
/* =====================================================================
 * OrsonPDF : a fast, light-weight PDF library for the Java(tm) platform
 * =====================================================================
 * //ww w .ja v  a 2 s . c  o  m
 * (C)opyright 2013-2015, by Object Refinery Limited.  All rights reserved.
 *
 * Project Info:  http://www.object-refinery.com/orsonpdf/index.html
 * 
 * This program 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.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
 * Other names may be trademarks of their respective owners.]
 * 
 * If you do not wish to be bound by the terms of the GPL, an alternative
 * commercial license can be purchased.  For details, please see visit the
 * Orson PDF home page:
 * 
 * http://www.object-refinery.com/orsonpdf/index.html
 * 
 */

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

public class Main {
    /**
     * Returns a string in standard PDF date format representing the specified 
     * date (in the default timezone).
     * 
     * @param date  the date ({@code null} not permitted).
     * 
     * @return A string in standard PDF date format. 
     */
    public static String toDateFormat(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return toPDFDateFormat(c);
    }

    /**
     * Returns a string in standard PDF date format representing the date 
     * contained by the specified calendar.
     * 
     * @param calendar  the date and timezone ({@code null} not permitted).
     * 
     * @return A string in standard PDF date format. 
     */
    public static String toPDFDateFormat(Calendar calendar) {
        Date d = calendar.getTime();
        DateFormat df1 = new SimpleDateFormat("yyyyMMddHHmmss");
        DateFormat df2 = new SimpleDateFormat("Z");
        String part1 = df1.format(d);
        String part2 = df2.format(d);
        String tzinfo;
        if (part2.equals("z")) {
            tzinfo = "Z00'00'";
        } else {
            tzinfo = part2.substring(0, 3) + "'" + part2.substring(4) + "'";
        }
        return "D:" + part1 + tzinfo;
    }
}

Related

  1. toDate(long time)
  2. toDate(Object o)
  3. ToDate(Object o)
  4. toDate(Object object)
  5. toDate(Object value)
  6. toDateFromLong(Long time)
  7. toDateHeader(long value)
  8. toDateList(Collection list)
  9. toDateQueryFormat(Date value)