Java String to Date toDateWithTimezone(String dateTime, String pattern)

Here you can find the source of toDateWithTimezone(String dateTime, String pattern)

Description

To date with timezone.

License

Open Source License

Parameter

Parameter Description
dateTime the date time
pattern the pattern

Exception

Parameter Description
ParseException the parse exception

Return

the date

Declaration

public static Date toDateWithTimezone(String dateTime, String pattern) throws ParseException 

Method Source Code


//package com.java2s;
/*//from   ww w  .  j  a  va  2  s  .c  o  m
 * DateUtil.java
 * Copyright (c) 2014, CODEROAD, All Rights Reserved.
 *
 * This software is the confidential and proprietary information of CODEROAD
 * ("Confidential Information"). You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you entered into with
 * CODEROAD.
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

public class Main {
    /**
     * To date with timezone.
     * 
     * @param dateTime the date time
     * @param pattern the pattern
     * @return the date
     * @throws ParseException the parse exception
     */
    public static Date toDateWithTimezone(String dateTime, String pattern) throws ParseException {

        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.ENGLISH);
        date = sdf.parse(dateTime);
        return date;
    }
}

Related

  1. toDateTimeFormat(String input, String inputfmt, String outputfmt)
  2. toDateTimeSSSString(long datetime)
  3. toDateTimeString(java.util.Date date)
  4. toDateTimeString(java.util.Date date)
  5. toDateWithFormatString(String date, String format)
  6. transformStringToDate(String dateString)
  7. translateToDate(String aDate, String aFormat)