Java Date to Time getTime(final Date time)

Here you can find the source of getTime(final Date time)

Description

Builds a string in the SimpleDateFormat of yyyyMMdd'T'HHmmss

License

Open Source License

Parameter

Parameter Description
time the time

Return

String representation of the SimpleDateFormat of yyyyMMdd'T'HHmmss in the specified time

Declaration

public static String getTime(final Date time) 

Method Source Code

//package com.java2s;
/**/*from  w w w .  j  a  va 2  s. c o m*/
 *    Created on Oct 21, 2010
 *    This file is part of JObexFTP 2.0, and it contains parts of OBEX4J.
 *
 *    JObexFTP is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    JObexFTP 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 Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with JObexFTP.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    /**
     * DateFormat for getTime
     * @see Utility#getTime(java.util.Date)
     */
    private static final DateFormat OBEX_DATE_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
    private static final DateFormat format = SimpleDateFormat.getInstance();

    /**
     * Builds a string in the SimpleDateFormat of yyyyMMdd'T'HHmmss
     * @param time the time
     * @return String representation of the SimpleDateFormat of yyyyMMdd'T'HHmmss in the specified time
     */
    public static String getTime(final Date time) {
        return OBEX_DATE_FORMAT.format(time);
    }

    /**
     * Gets a long representation of a yyyyMMdd'T'HHmmss time representated String
     * @param value
     * @return
     * @see Utility#getTime(java.util.Date)
     */
    public static Date getTime(final String value) {
        Calendar c = GregorianCalendar.getInstance();
        int year = Integer.parseInt(value.substring(0, 4));
        int month = Integer.parseInt(value.substring(4, 6));
        int date = Integer.parseInt(value.substring(6, 8));
        int hrs = Integer.parseInt(value.substring(9, 11));
        int min = Integer.parseInt(value.substring(11, 13));
        int sec = Integer.parseInt(value.substring(13, 15));
        c.set(year, month - 1, date, hrs, min, sec);
        return c.getTime();
    }
}

Related

  1. getTime(Date dateParam)
  2. getTime(Date executionTime)
  3. getTime(Date timestamp)
  4. getTime(Date trialTime)
  5. getTime(final Date date, final int day)
  6. getTime(java.util.Date date)
  7. getTime(java.util.Date date)
  8. getTime(java.util.Date date)
  9. getTimeAsMilliSeconds(Date dateTime)