2012-04-17 8 views
0

私はSQLiteを使用して、ブラックベリー日時フィールドに自分の日付を取得しようとしています。 DBでJavaME日付文字列を長く

その形式の文字列として格納さ:

yyyy-MM-dd HH:mm

例えば:2012-02-01 15:45

しかし、フィールドはLongとしてそれを望んでいます。

date - The initial date value for this field. This is the number of milliseconds since midnight on January 1, 1970. To create an empty date field, set this parameter to Long.MIN_VALUE. This method will then remove the date value from this field, setting it to null.

そして再びそれを変換。次のコード

答えて

4

チェック:

// conversion - string to long 
long dateLong = HttpDateParser.parse("2012-04-17 16:09"); 

// conversion - long to string 
Date dateObject = new Date(dateLong);   
String dateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm")).format(dateObject); 
+0

は素晴らしい作品。どのようにして元気いっぱいに戻すことができますか?私は実際には戻って時間が必要ない。 – Doomsknight

+0

コードを今すぐ確認してください。あなたがあなたのデータをどのような形式で戻す必要があるのか​​を、「何度も元に戻す方法」と混同しています。 'Date'か' String'を使うことができます。 – Rupak

+0

優れた回答。うん、私は文字列の形式で日付を意味する、別名、文字列に戻る。どうもありがとう :) – Doomsknight

関連する問題