我有这段代码:
String id = c.getString("data");
String name = ((TextView) view.findViewById(R.id.TextView05)).getText().toString();
public static String getDate(long seconds, String dateFormat)
{
DateFormat formatter = new SimpleDateFormat("yyyy MMMM dd HH:mm");
long now = System.currentTimeMillis();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(now);
return formatter.format(calendar.getTime());
}
"data"
是1341435600000
。我希望这个字符串从毫秒到现在。
答案 0 :(得分:0)
try {
String str_date="11-June-07";
DateFormat formatter ;
Date date ;
formatter = new SimpleDateFormat("dd-MMM-yy");
date = (Date)formatter.parse(str_date);
System.out.println("Today is " +date );
}
catch (ParseException e)
{
System.out.println("Exception :"+e);
}
将转换毫秒数转换为日期
long yourmilliseconds = 1119193190;
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
Date resultdate = new Date(yourmilliseconds);
答案 1 :(得分:0)
这样的事情:
SimpleDateFormat ss = (SimpleDateFormat) SimpleDateFormat.getInstance();
ss.applyPattern("yyyy MM dd HH:mm");
// Date to String:
String dateToString = ss.format(new Date());
//String to Date
Date stringToDate = ss.parse("2012 02 16 14:10"));
答案 2 :(得分:0)
String dtStart = "2010-10-15T09:27:37Z";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
try {
Date date = format.parse(dtStart);
System.out.println(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
答案 3 :(得分:0)
同样的方法对我来说很好。你为什么不呢?
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
long cTime = System.currentTimeMillis();
String date = getDate(cTime, "dd/MM/yyyy hh:mm:ss.SSS");
Toast.makeText(getApplicationContext(), date, Toast.LENGTH_SHORT).show();
}
public static String getDate(long milliSeconds, String dateFormat)
{
// Create a DateFormatter object for displaying date in specified format.
DateFormat formatter = new SimpleDateFormat(dateFormat);
// Create a calendar object that will convert the date and time value in milliseconds to date.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliSeconds);
return formatter.format(calendar.getTime());
}
答案 4 :(得分:0)
如果您对Date
格式不感兴趣,请按以下方式使用
String id = c.getString("data"); //"1341435600000";
Date date123 = new Date(Long.parseLong(id));
System.out.println(date123);
答案 5 :(得分:0)
要提供帮助的代码段:
String timestamp="20140809";
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
System.out.println("date :"+dateFormat.parse(timestamp).getTime());