Java String to Time stringToCalendar(String timeStr)

Here you can find the source of stringToCalendar(String timeStr)

Description

string To Calendar

License

Open Source License

Declaration

public static Calendar stringToCalendar(String timeStr) 

Method Source Code

//package com.java2s;
/**/*from www . j  av a 2 s  .  co  m*/
 * Program  : CommonsFiend.java
 * Author   : niehai
 * Create   : 2008-5-14 ????05:05:54
 *
 * Copyright 2007 by Embedded Internet Solutions Inc.,
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Embedded Internet Solutions Inc.("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 Embedded Internet Solutions Inc.
 *
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

public class Main {
    public static Calendar stringToCalendar(String timeStr) {
        Date date = stringToTime(timeStr);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar;
    }

    public static Date stringToTime(String timeStr) {
        Date date = new Date();
        SimpleDateFormat apf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            date = apf.parse(timeStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static Date stringToTime(String timeStr, String formatString) {
        Date date = new Date();
        SimpleDateFormat apf = new SimpleDateFormat(formatString);
        try {
            date = apf.parse(timeStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}

Related

  1. str2DateTime(String strDate)
  2. string2Date(String time)
  3. string2DateTime(String stringDate)
  4. string2DateTimeByAutoZero(String stringDate)
  5. stringToCalendar(String stringTime)
  6. stringToTimeDate(String timeStr)
  7. toTime(final String dateString)
  8. toTime(String display)
  9. toTime(String str)