如何获得的那一天,一年,小时,分钟单独从日期格式" YYYY-MM-dd'T'HH:MM:ss.SSSZ"? [英] How to get the day, year, hours, min Individually from date format "yyyy-MM-dd'T'HH:mm:ss.SSSZ"?

查看:1862
本文介绍了如何获得的那一天,一年,小时,分钟单独从日期格式" YYYY-MM-dd'T'HH:MM:ss.SSSZ"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个程序,存储present时间和日期YYYY-MM-dd'T'HH:MM:ss.SSSZ此格式。与我将其存储在数据库中作为字符串。当我收集的资料,我需要像一天,一年,分个人价值,秒等。我怎么能做到这一点?

I am doing a programme that stores the present time and date in "yyyy-MM-dd'T'HH:mm:ss.SSSZ" this format. and I am storing it in database as a string. when i am collecting the data i need the individual values like day, year, min, seconds etc.. how can i do this?

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
String now = formatter.format(new Date());

感谢您,

推荐答案

我建议你在数据库存储倍timeInMillis。在我的经验,它简化了code,它可以让你倍的值进行比较的海誓山盟。

I'm suggesting that you store times in the DB as "timeInMillis". In my experience it simplifies code and it allows you to compare times values to eachother.

要存储时间:

Calendar calendar = Calendar.getInstance(); // current time
long timeInMillis = calendar.gettimeinmillis();
mDb.saveTime (timeInMillis); // adjust this to work with your DB

要检索时间:

long timeInMillis = mDb.getTime();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis (timeInMillis);
int milliSeconds = calendar.get(MILLISECOND);
//etc

这篇关于如何获得的那一天,一年,小时,分钟单独从日期格式" YYYY-MM-dd'T'HH:MM:ss.SSSZ"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆