현재 날짜 및 시간 가져 오기

자 이민 모디

다음과 같이 Android 응용 프로그램에서 현재 datetime에 액세스하려고했습니다.

 Calendar c = Calendar.getInstance();
 int seconds = c.get(Calendar.SECOND);
            //long time = System.currentTimeMillis();
 Date date2 = new Date(seconds);
 Log.d(">>>>>>>Current Date : ",""+date2);

1970 년의 날짜와 시간을 다음과 같이 알려줍니다.

>>>>>>>Current Date :﹕ Thu Jan 01 05:30:00 GMT+05:30 1970

하지만 1970 년이 아닌 2015 년이되어야합니다. 문제는 무엇입니까?

제공된 솔루션에서 위의 문제를 해결했습니다. Atually, 나는 databse의 datetime 값이 현재 datetime 값과 일치함에 따라 알림을 생성하고 있습니다. 그러나 알림을 생성하지 않습니다.

내 코드는 다음과 같습니다.

public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);
    doAsynchTask = new TimerTask() {

        @Override
        public void run() {
            Log.d("Timer Task Background", "Timer task background");
            Calendar c = Calendar.getInstance();
            c.setTime(new Date());
            long time = System.currentTimeMillis();
            Date dateCurrent = new Date(time);
            Log.d(">>>>>>>Current Date : ", "" + dateCurrent);

            getListData();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm a");
            Date dateFromDatabase;
            for (int i = 0; i < remiderList.size(); i++) {

                try {
                    System.out.print("+++" + remiderList.get(i).toString());
                    dateFromDatabase = formatter.parse(remiderList.get(i).toString());
                    Log.d(">>>>>Database date  : ", "" + dateFromDatabase);
                    if (dateCurrent.equals(dateFromDatabase)) {
                        Toast.makeText(getApplicationContext(), "Date matched", Toast.LENGTH_LONG).show();

                        displayNotification();
                    }


                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }

    };
    timer.schedule(doAsynchTask, 0, 1000);


}

public void displayNotification() {
    Notification.Builder builder = new Notification.Builder(MyRemiderService.this);


    Intent intent1 = new Intent(this.getApplicationContext(),
            HomeActivity.class);
    Notification notification = new Notification(R.drawable.notification_template_icon_bg,
            "This is a test message!", System.currentTimeMillis());
    intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
            | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingNotificationIntent = PendingIntent.getActivity(
            this.getApplicationContext(), 0, intent1,
            PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setSmallIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha)
            .setContentTitle("ContentTitle").setContentText("this for test massage")
            .setContentIntent(pendingNotificationIntent);

    notification = builder.getNotification();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
   /* notification.setLatestEventInfo(this.getApplicationContext(),
            "AlarmManagerDemo", "This is a test message!",
            pendingNotificationIntent);*/

    mManager.notify(0, notification);
}

@Override
public void onDestroy() {

    super.onDestroy();
}

public void getListData() {
    remiderList = dbHelper.getAllRemiders();
}

다음과 같이 Logcat에서 두 값을 모두 확인했습니다.

09-15 17:50:00.629  17915-17927/? D/>>>>>>>Current Date :﹕ Tue Sep 15 17:50:00 GMT+05:30 2015

09-15 17:50:00.637  17915-17927/? D/>>>>>Database date  :﹕ Tue Sep 15 17:50:00 GMT+05:30 2015
자히르 코라 지야

캘린더 개체에 현재 날짜를 설정하지 않았습니다.

 Calendar c = Calendar.getInstance();
    c.setTime(new Date());
    //Calendar.SECOND will return only seconds from the date
    //int seconds = c.get(Calendar.SECOND);
    long time = c.getTime();
    Date date2 = new Date(time);
    Log.d(">>>>>>>Current Date : ",""+date2);

SimpleDateFormat 클래스를 사용하여 다음과 같이 날짜 형식을 지정할 수 있습니다.

SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
System.out.println(format.format(new Date()));

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Android : 현재 날짜 및 시간 가져 오기

분류에서Dev

PHP에서만 현재 날짜 및 시간 가져 오기

분류에서Dev

Android의 Google에서 현재 날짜 및 시간 가져 오기

분류에서Dev

GitHub 워크 플로에서 현재 날짜 및 시간 가져 오기

분류에서Dev

현지 날짜 및 시간대에서 epoch millis 가져 오기

분류에서Dev

현재 날짜 및 시간 오작동

분류에서Dev

현재 날짜 wrt 시간대 가져 오기

분류에서Dev

Android 장치에서 현재 날짜 / 시간 가져 오기

분류에서Dev

현재 시간 및 날짜

분류에서Dev

현재 날짜 및 고정 시작 날짜를 기반으로 날짜 열을 가져옵니다.

분류에서Dev

현재 날짜 및 요일 목록을 기반으로 날짜 가져 오기

분류에서Dev

awk 및 date로 현재 날짜 가져 오기

분류에서Dev

날짜 및 시간에 대한 GMT 시간 가져 오기

분류에서Dev

현재 날짜를 가져 오지만 SET 시간 UNIX

분류에서Dev

ElasticSearch가 항상 오른쪽에있는 Grafana 주석 (현재 날짜 및 시간)

분류에서Dev

git에 메시지를 커밋 할 현재 날짜와 시간 가져 오기

분류에서Dev

날짜 : 현재 15 분 간격 가져 오기

분류에서Dev

Moment.js-미리 정의 된 시간으로 현재 날짜 가져 오기

분류에서Dev

날짜 및 시간 기반 데이터 가져 오기

분류에서Dev

WordPress에서 현재 시간 및 현재 시간대 가져 오기 문제

분류에서Dev

특정 시간 및 날짜에 systime 가져 오기-Oracle SQL

분류에서Dev

xlsx 가져 오기에서 날짜 및 시간 구문 분석

분류에서Dev

날짜 및 시간 양식 postgresql 가져 오기

분류에서Dev

Excel 데이터 가져 오기 및 날짜 시간 유지

분류에서Dev

일, 시간, 분 및 초 (AM / PM 날짜)로 날짜 차이 가져 오기

분류에서Dev

Django에서 현재 날짜 (및 시간) 얻기

분류에서Dev

현재 날짜 및 시간 표시

분류에서Dev

momentjs에서 현지 날짜 시간 json 가져 오기

분류에서Dev

Kotlin : 두 날짜 (현재 날짜와 이전 날짜) 간의 차이 가져 오기

Related 관련 기사

  1. 1

    Android : 현재 날짜 및 시간 가져 오기

  2. 2

    PHP에서만 현재 날짜 및 시간 가져 오기

  3. 3

    Android의 Google에서 현재 날짜 및 시간 가져 오기

  4. 4

    GitHub 워크 플로에서 현재 날짜 및 시간 가져 오기

  5. 5

    현지 날짜 및 시간대에서 epoch millis 가져 오기

  6. 6

    현재 날짜 및 시간 오작동

  7. 7

    현재 날짜 wrt 시간대 가져 오기

  8. 8

    Android 장치에서 현재 날짜 / 시간 가져 오기

  9. 9

    현재 시간 및 날짜

  10. 10

    현재 날짜 및 고정 시작 날짜를 기반으로 날짜 열을 가져옵니다.

  11. 11

    현재 날짜 및 요일 목록을 기반으로 날짜 가져 오기

  12. 12

    awk 및 date로 현재 날짜 가져 오기

  13. 13

    날짜 및 시간에 대한 GMT 시간 가져 오기

  14. 14

    현재 날짜를 가져 오지만 SET 시간 UNIX

  15. 15

    ElasticSearch가 항상 오른쪽에있는 Grafana 주석 (현재 날짜 및 시간)

  16. 16

    git에 메시지를 커밋 할 현재 날짜와 시간 가져 오기

  17. 17

    날짜 : 현재 15 분 간격 가져 오기

  18. 18

    Moment.js-미리 정의 된 시간으로 현재 날짜 가져 오기

  19. 19

    날짜 및 시간 기반 데이터 가져 오기

  20. 20

    WordPress에서 현재 시간 및 현재 시간대 가져 오기 문제

  21. 21

    특정 시간 및 날짜에 systime 가져 오기-Oracle SQL

  22. 22

    xlsx 가져 오기에서 날짜 및 시간 구문 분석

  23. 23

    날짜 및 시간 양식 postgresql 가져 오기

  24. 24

    Excel 데이터 가져 오기 및 날짜 시간 유지

  25. 25

    일, 시간, 분 및 초 (AM / PM 날짜)로 날짜 차이 가져 오기

  26. 26

    Django에서 현재 날짜 (및 시간) 얻기

  27. 27

    현재 날짜 및 시간 표시

  28. 28

    momentjs에서 현지 날짜 시간 json 가져 오기

  29. 29

    Kotlin : 두 날짜 (현재 날짜와 이전 날짜) 간의 차이 가져 오기

뜨겁다태그

보관