Here you can find the source of getCalendar(String timeStamp, final String dateFormat)
Parameter | Description |
---|---|
timeStamp | the time stamp |
dateFormat | the date format |
Parameter | Description |
---|---|
ParseException | the parse exception |
public static Calendar getCalendar(String timeStamp, final String dateFormat) throws ParseException
//package com.java2s; /*/*from w w w .j av a2 s . com*/ * DateUtil.java * Copyright (c) 2014, EcoFactor, All Rights Reserved. * * This software is the confidential and proprietary information of EcoFactor * ("Confidential Information"). You shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement you entered into with * EcoFactor. */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; public class Main { public static final String DATE_FMT_FULL = "yyyy-MM-dd HH:mm:ss aa"; /** * Gets the calendar. * @param timeStamp the time stamp * @param dateFormat the date format * @return the calendar * @throws ParseException the parse exception */ public static Calendar getCalendar(String timeStamp, final String dateFormat) throws ParseException { DateTime dt = new DateTime(DateTimeZone.UTC); Calendar calendar = dt.toCalendar(Locale.ENGLISH); SimpleDateFormat sdf = new SimpleDateFormat(DATE_FMT_FULL, Locale.ENGLISH); Date date = sdf.parse(timeStamp); calendar.setTime(date); return calendar; } /** * Gets the calendar. * @param startTime the start time * @param minutes the minutes * @return the calendar */ public static Calendar getCalendar(Calendar startTime, int minutes) { Calendar endTime = null; DateTime start = new DateTime(startTime); DateTime end = start.plusMinutes(minutes); DateTimeFormatter fmt = DateTimeFormat.forPattern(DATE_FMT_FULL); fmt = fmt.withZoneUTC(); endTime = parseToUTCCalendar(fmt.print(end), DATE_FMT_FULL); return endTime; } /** * Format. * @param timestamp the timestamp * @param pattern the pattern * @return the string */ public static Calendar parseToUTCCalendar(String timestamp, String pattern) { DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern); fmt = fmt.withZoneUTC(); DateTime dt = fmt.parseDateTime(timestamp); dt = dt.toDateTime(DateTimeZone.UTC); return dt.toCalendar(Locale.ENGLISH); } }