Here you can find the source of dateToString(final Date value, final boolean utc)
Parameter | Description |
---|---|
value | The date. |
utc | Boolean, whether to format the time in UTC or the local time zone. |
public static String dateToString(final Date value, final boolean utc)
//package com.java2s; /*/* w w w. ja v a 2s .c o m*/ * Copyright 2013 * * 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.TimeZone; public class Main { /** * Initializes a SimpleDateFormat for use if UTC is not enabled * * @since org.openntf.domino 1.0.0 */ private static ThreadLocal<SimpleDateFormat> ISO_LOCAL = new ThreadLocal<SimpleDateFormat>() { @Override protected SimpleDateFormat initialValue() { return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); } }; /** * Initializes a SimpleDateFormat for use if UTC is enabled * * @since org.openntf.domino 1.0.0 */ private static ThreadLocal<SimpleDateFormat> ISO_UTC_LOCAL = new ThreadLocal<SimpleDateFormat>() { @Override protected SimpleDateFormat initialValue() { SimpleDateFormat ISO8601_UTC = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); //$NON-NLS-1$; TimeZone tz = TimeZone.getTimeZone("UTC"); ISO8601_UTC.setTimeZone(tz); return ISO8601_UTC; } }; /** * Converts a date to an ISO8601 string. * * @param value * The date. * @param utc * Boolean, whether to format the time in UTC or the local time zone. * @return The ISO8601 string. * @since org.openntf.domino 1.0.0 */ public static String dateToString(final Date value, final boolean utc) { String result = null; if (utc) { result = ISO_UTC_LOCAL.get().format(value); } else { result = ISO_LOCAL.get().format(value); } return result; } }