Java Date UTC Parse parseToUTCDate(String timestamp, String pattern)

Here you can find the source of parseToUTCDate(String timestamp, String pattern)

Description

Format.

License

Open Source License

Parameter

Parameter Description
timestamp the timestamp
pattern the pattern

Return

the string

Declaration

public static Date parseToUTCDate(String timestamp, String pattern) 

Method Source Code


//package com.java2s;
/*//from w w w  . j a v  a2 s  .  com
 * DateUtil.java
 * Copyright (c) 2014, EcoFactor, All Rights Reserved.
 *
 * This software is the confidential and proprietary information of EcoFactor
 * ("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
 * EcoFactor.
 */

import java.text.ParseException;

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

import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

public class Main {
    /**
     * Format.
     * @param timestamp the timestamp
     * @param pattern the pattern
     * @return the string
     */
    public static Date parseToUTCDate(String timestamp, String pattern) {

        DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
        fmt = fmt.withZoneUTC();
        Date date = fmt.parseDateTime(timestamp).toDate();
        return date;
    }

    /**
     * To date.
     * @param calendar the calendar
     * @return the date
     * @throws ParseException the parse exception
     */
    public static Date toDate(final Calendar calendar) throws ParseException {

        Date date = new Date();
        date = calendar.getTime();
        return date;
    }
}

Related

  1. getUTCDate(int year, int month, int date, int h, int m, int s, int milli)
  2. getUTCDate(int year, int month, int day)
  3. getUTCMidnightZero(Date d)
  4. parseDateAsUTC(String dateString)
  5. parsePartialUTCToDate(String utcDate)
  6. parseUTCDateToString(Date date)
  7. parseUTCToDate(String utcDate)
  8. toUTC(Date date)
  9. toUTC(Date date)