UNITY_C#

유니티_날짜와 시간 기록,저장하고 불러오기 DateTime

쫑나리 2023. 9. 20. 16:55
728x90
반응형
SMALL

DateTime을 사용하여 현재 시간을 받아오고,

저장해두고,

다음 접속 시 마지막 접속 기록을 함께 불러올 것입니다.

PlayerPrefs를 사용하여 기록 저장!

https://narii.tistory.com/52

public class DateCheck : MonoBehaviour
{
    System.DateTime now;
    int nowMonth;
    int nowDay;
    int nowHour;
    int nowMinute;

    void Start()
    {	//현재 날짜와 시간
        now = System.DateTime.Now;
        nowMonth = now.Month;   
        nowDay = now.Day;
        nowHour = now.Hour;
        nowMinute = now.Minute;

        // 이전에 실행했던 날짜 얻기
        int oldMonth = PlayerPrefs.GetInt("Month");
        int oldDay = PlayerPrefs.GetInt("Day");
        int oldHour = PlayerPrefs.GetInt("Hour");
        int oldMinute = PlayerPrefs.GetInt("Minute");

        Debug.Log(		//최근 접속일시와 현재 시간
        	"이전 실행일 : " + oldMonth + "월 " + oldDay + "일" + 
        	oldHour + "시" + oldMinute + "분\n"
        	+ "현재 실행일 : " + nowMonth + "월 " + nowDay + "일" + 
            nowHour +"시" + nowMinute +"분");

        // 현재 실행한 날짜와 시간을 기록
        PlayerPrefs.SetInt("Month", nowMonth);
        PlayerPrefs.SetInt("Day", nowDay);
        PlayerPrefs.SetInt("Hour", nowHour);
        PlayerPrefs.SetInt("Minute", nowMinute);
	}

}

 

728x90
반응형
LIST