Android Date String Parse parseIcalDateToString(Date date, TimeZone tz)

Here you can find the source of parseIcalDateToString(Date date, TimeZone tz)

Description

Pase the Ical Date to a String

License

Open Source License

Parameter

Parameter Description
date the date
tz timezone

Return

the parsed Date as a String

Declaration

private static String parseIcalDateToString(Date date, TimeZone tz) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;
import java.util.TimeZone;

public class Main {
    /**//from  ww w  .  java 2 s.c  o m
     * Pase the Ical Date to a String
     * 
     * @param date
     *            the date
     * @param tz
     *            timezone
     * @return the parsed Date as a String
     */
    private static String parseIcalDateToString(Date date, TimeZone tz) {

        StringBuilder sb = new StringBuilder();
        SimpleDateFormat timeFormat = new SimpleDateFormat("HHmm",
                Locale.getDefault());
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd",
                Locale.getDefault());

        if (tz != null) {
            timeFormat.setTimeZone(tz);
            dateFormat.setTimeZone(tz);
        } else {
            timeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
            dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        }

        sb.append(dateFormat.format(date));
        sb.append("T");
        sb.append(timeFormat.format(date));
        sb.append("00");

        if (tz == null)
            sb.append('Z');

        return sb.toString();
    }
}

Related

  1. getDateFromString(String format, String dateString)
  2. getDateFromLJString( String dateString)
  3. getDateFromString(String dateString)
  4. parseRFC3339Date(String date)
  5. parseRFC822Date(String date)
  6. parseDate(String s)
  7. parseDate(String value)
  8. parseLastfmDate(String date)
  9. parseLastfmDateAlbum(String date)