Here you can find the source of parseDateFromJsonArray(final JsonArray array)
Parameter | Description |
---|---|
array | the JsonArray of the date in the form of [year, month, day] |
Parameter | Description |
---|---|
ParseException | an exception |
public static Date parseDateFromJsonArray(final JsonArray array) throws ParseException
//package com.java2s; /**//from ww w .j a v a2s. c o m * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ import com.google.common.base.Preconditions; import com.google.gson.JsonArray; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.GregorianCalendar; public class Main { /** * Parses a {@link JsonArray} to a {@link Date}. * @param array the {@link JsonArray} of the date in the form of [year, month, day] * @return a {@link Date} parsed in the "dd MMMM yyyy" format * @throws ParseException */ public static Date parseDateFromJsonArray(final JsonArray array) throws ParseException { Preconditions.checkNotNull(array); final GregorianCalendar calendar = new GregorianCalendar(array.get(0).getAsInt(), array.get(1).getAsInt() - 1, array.get(2).getAsInt()); final SimpleDateFormat format = new SimpleDateFormat("dd MMMM yyyy"); return format.parse(format.format(calendar.getTime())); } }