DateTime 과 TImeStamp int 간 전환

파이어 베이스에 TimeStamp를 보낼때는

Timestamp.FromDateTime(dateTime); 형태로 변환해서 넘겨야한다!

 

public static readonly System.DateTime SPAN_TIME 
	= new System.DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime();

public static DateTime GetDateTime(int timestamp)
{
    DateTime origin = SPAN_TIME;
    return origin.AddSeconds(timestamp);
}

public static int GetUnixTime()
{
    var now = System.DateTime.Now.ToLocalTime();
    var span = now - SPAN_TIME;
    return (int)span.TotalSeconds;
}

 

 

 

'Unity > 파이어베이스' 카테고리의 다른 글

파이어 베이스 출시 후 정상작동안할 때  (0) 2021.11.19
파이어베이스 보안 규칙  (0) 2020.09.17
FireBase 기본 연동  (0) 2020.09.13

댓글

Designed by JB FACTORY