Here you can find the source of utcToLocal(Date date)
Parameter | Description |
---|---|
date | the date |
public static String utcToLocal(Date date)
//package com.java2s; /*//from w ww. java 2 s.co m * Copyright (c) 2016 Martin Pfeffer * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss"; public static final String UTC_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; /** * Utc to local string. * * @param date the date * @return the string */ public static String utcToLocal(Date date) { try { SimpleDateFormat sdf = new SimpleDateFormat(UTC_FORMAT); sdf.applyPattern(DEFAULT_FORMAT); return sdf.format(date); } catch (Exception e) { e.printStackTrace(); return null; } } /** * Utc to local string. * * @param date the date * @param locale the locale * @return the string */ public static String utcToLocal(Date date, Locale locale) { try { SimpleDateFormat sdf = new SimpleDateFormat(UTC_FORMAT, locale); sdf.applyPattern(DEFAULT_FORMAT); return sdf.format(date); } catch (Exception e) { e.printStackTrace(); return null; } } }