Here you can find the source of setDateTimeByString(Calendar theDateTime, String str)
Parameter | Description |
---|---|
theDateTime | a parameter |
str | a parameter |
public static void setDateTimeByString(Calendar theDateTime, String str)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; public class Main { /**/*from www . j a va 2 s .c o m*/ * set the calendar value of theDateTime according to a string like "2008-08-08T08:08:08" * @param theDateTime * @param str */ public static void setDateTimeByString(Calendar theDateTime, String str) { str = str.trim(); String year, month, day; int i1, i2, iT; i1 = str.indexOf("-"); i2 = str.indexOf("-", i1 + 1); iT = str.indexOf('T'); year = str.substring(0, i1); month = str.substring(i1 + 1, i2); day = str.substring(i2 + 1, iT); i1 = str.indexOf(':', iT + 1); i2 = str.indexOf(':', i1 + 1); theDateTime.set(Calendar.MILLISECOND, 0); theDateTime.set(Calendar.SECOND, Integer.parseInt(str.substring(i2 + 1))); theDateTime.set(Calendar.MINUTE, Integer.parseInt(str.substring(i1 + 1, i2))); theDateTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(str.substring(iT + 1, i1))); theDateTime.set(Calendar.DAY_OF_MONTH, 1); theDateTime.set(Calendar.MONTH, Integer.parseInt(month, 10) - 1); theDateTime.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day, 10)); theDateTime.set(Calendar.YEAR, Integer.parseInt(year, 10)); } }