Java UTC Date getUtcDate(String date, String pattern)

Here you can find the source of getUtcDate(String date, String pattern)

Description

get Utc Date

License

Apache License

Declaration

@SuppressWarnings("deprecation")
public static String getUtcDate(String date, String pattern) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class Main {

    @SuppressWarnings("deprecation")
    public static String getUtcDate(String date, String pattern) {
        try {/*from ww w . j av  a2  s  .  co m*/
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Date now = Calendar.getInstance().getTime();
            Date theDate = format.parse(date);
            theDate.setHours(now.getHours());
            theDate.setMinutes(now.getMinutes());
            format.setTimeZone(TimeZone.getTimeZone("UTC"));
            format.applyPattern(pattern);
            return format.format(theDate);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. getUTCCalendar()
  2. getUTCCalendar()
  3. getUTCCalendar(Calendar value)
  4. getUTCCalendarFromDialogString(String dateString)
  5. getUTCDate()
  6. getUTCDateFromString(String date)
  7. getUtcDateString()
  8. getUtcDateStringFromTimestamp(Date timeStamp)
  9. GetUTCdatetimeAsString()