0

私は何かに行き詰まっています。私が望むのは、システムの日付と時刻を取得し、それを文字列に格納し、次にランダムな時間を他の文字列に追加し、if else (例:

if(dateTime1 > dateTime2) {

}

次に、gmailに表示されるようなメッセージを表示したい(メールが今日送信された場合、gmailは今日の午後5時に時刻を表示します)。そして、それらすべてを text Boxes に表示したいと思います。今日の午後 4 時、昨日の午後 4 時のようなメッセージが必要です。1 週間を超えた場合は、日付と時刻を表示するだけです。あなたの助けが必要です。親切に私を助けてください。これは私がこれまでに行ったことです。また、他の多くのことを試しました。

 public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TextView ShowDate = (TextView) findViewById(R.id.ShowDate);
    TextView ShowToday = (TextView) findViewById(R.id.ShowToday);
    TextView ShowWeek  = (TextView) findViewById(R.id.ShowWeek );
    TextView ShowAgo  = (TextView) findViewById(R.id.ShowAgo ); 
    Calendar ci = Calendar.getInstance();

    String CiDateTime = "" + ci.get(Calendar.YEAR) + "-" +
        (ci.get(Calendar.MONTH) + 1) + "-" +
        ci.get(Calendar.DAY_OF_MONTH) + " " +
        ci.get(Calendar.HOUR) + ":" +
        ci.get(Calendar.MINUTE) +  ":" +
        ci.get(Calendar.SECOND);
4

3 に答える 3

0

これは、日付を文字列形式で保存するのに役立ちます -SimpleDateFormat

gmailのようなテキストビューで時間を表示するには、現在の時間をストア時間で確認する必要があります。これは、文字列からデータへの単純な日付形式から取得されます。日付の比較については、これを参照して ください-日付の比較

于 2014-04-08T11:12:59.360 に答える
0

ああ、私のコードで作成する ua の例を示します。現在の時間の diff を取り、1970 年 1 月 1 日から時間の diff を計算します。使用です

 Calendar cal = Calendar.getInstance();
    Date currentLocalTime = cal.getTime();
    DateFormat date = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");  
    date.setTimeZone(TimeZone.getTimeZone("GMT")); 
    String localTime = date.format(currentLocalTime); 

    long currenttime = Constant.retunlongdate(localTime);
    long fixtimejan = Constant.retunlongdate("01/01/1970 00:00:00 AM");

    long nTimeStamp = (currenttime - fixtimejan)/1000;
    System.out.println("and result is == " + nTimeStamp);

 public static long retunlongdate(String givenDateString)
        {

        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a"); 

        long timeInMilliseconds=0;
        try {
            Date mDate =sdf.parse(givenDateString);
              timeInMilliseconds = mDate.getTime();
            System.out.println("Date in milli :: " + timeInMilliseconds);
            return timeInMilliseconds;
        } catch (ParseException e) {
                    e.printStackTrace();
        } catch (java.text.ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
    }
        return timeInMilliseconds;
    }
于 2014-04-08T11:21:24.420 に答える