Android: Convert date to milliseconds

后端 未结 7 1299
囚心锁ツ
囚心锁ツ 2021-01-02 13:01

I used

SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy, HH:mm");
String time = formatter.format(new Date());

to get t

7条回答
  •  孤独总比滥情好
    2021-01-02 13:43

    Using this method you can Convert your Date Into miliseconds that can be used to add events to the Calender

    public Long GettingMiliSeconds(String Date)
        {
            long timeInMilliseconds = 0;
    
            SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
            try {
    
                Date mDate = sdf.parse(Date);
                timeInMilliseconds = mDate.getTime();
    
            } catch (ParseException  e) {
                e.printStackTrace();
            }
    
            return  timeInMilliseconds;
        }
    

提交回复
热议问题