Here you can find the source of dateToUtcString(Date date)
Parameter | Description |
---|---|
date | date to format |
public static String dateToUtcString(Date date)
//package com.java2s; /*//from ww w .jav a2s . c o m * Copyright (C) 2016 AT&T Intellectual Property. All rights reserved. * Copyright (c) 2016 Brocade Communications Systems, Inc. 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 */ import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { private static final TimeZone TZ_UTC = TimeZone.getTimeZone("UTC"); private static final String[] DATE_AND_TIME_FORMATS = { "yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" }; /** * Transform given {@link Date} into {@link String} using pattern * yyyy-MM-dd'T'HH:mm:ss'Z'. * * @param date * date to format * @return String */ public static String dateToUtcString(Date date) { final SimpleDateFormat sdf = new SimpleDateFormat(DATE_AND_TIME_FORMATS[0]); sdf.setTimeZone(TZ_UTC); return sdf.format(date); } }