0

我有这个代码:

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。_ 我想要从毫秒到日期的这个字符串。

4

6 回答 6

0

如果您不介意Date格式,请按以下方式使用

String id = c.getString("data"); //"1341435600000"; 
Date date123 = new Date(Long.parseLong(id));
System.out.println(date123);
于 2012-07-31T11:02:34.937 回答
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());
}
于 2012-07-31T10:52:29.590 回答
0

帮助的代码片段:

String timestamp="20140809";
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
System.out.println("date :"+dateFormat.parse(timestamp).getTime());
于 2014-09-10T20:02:29.787 回答
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);
于 2012-07-31T10:47:20.227 回答
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"));
于 2012-07-31T10:48:25.780 回答
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();  
}
于 2012-07-31T10:49:14.593 回答