Split date/time strings

后端 未结 7 1846
不思量自难忘°
不思量自难忘° 2020-12-18 03:32

I have a ReST service which downloads information about events in a persons calendar...

When it returns the date and time, it returns them as a string

e.g. d

相关标签:
7条回答
  • 2020-12-18 04:00

    Try this:

    String date = "12/8/2012";
    String time = "11:25 am";
    
    String[] date1 = date.split("/");
    String[] time1 = time.split(":");
    String[] time2 = time1[1].split(" ");  // to remove am/pm
    
    Calendar beginTime = Calendar.getInstance();
    beginTime.set(Integer.parseInt(date1[2]), Integer.parseInt(date1[1]), Integer.parseInt(date1[0]), Integer.parseInt(time1[0]), Integer.parseInt(time2[0]));
    startMillis = beginTime.getTimeInMillis();
    intent.put(Events.DTSTART, startMillis);
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题