Java String to Date toDate(final Long date, final String pattern)

Here you can find the source of toDate(final Long date, final String pattern)

Description

to Date

License

Open Source License

Declaration

public static String toDate(final Long date, final String pattern) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014, 2015 Red Hat.//from  ww w. j  ava 2  s  .c  o m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Red Hat - Initial Contribution
 *******************************************************************************/

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static String toDate(final Long date, final String pattern) {
        final long millis = Long.valueOf(date).longValue() * 1000;
        final Date d = new Date(millis);
        final SimpleDateFormat sdf = new SimpleDateFormat(pattern); //$NON-NLS-1$
        return sdf.format(d);
    }

    public static String toDate(final Date date, final String pattern) {
        final SimpleDateFormat sdf = new SimpleDateFormat(pattern); //$NON-NLS-1$
        return sdf.format(date);
    }
}

Related

  1. strToDatetime(String sStr)
  2. strToDateWithFormat(String strDate, Format format)
  3. TimeStringToDate(String s)
  4. timeToDate(String time)
  5. toDate(DateFormat format, String value)
  6. toDate(final String _text, final String _dateFormat)
  7. toDate(final String date, final String time)
  8. toDate(final String dateString, final String format)
  9. toDate(final String dateString, final String pattern)