Devavrata
Devavrata

Reputation: 311

In App purchase response which purchase time, convert this timestamp value to date format?

In-App purchase response, as purchase time, how to convert this timestamp to date format, the problem I am facing is the value of timestamp is exceeding long data type limit? kindly explain how to finad the date from timestamp in this case?

Upvotes: 4

Views: 2341

Answers (2)

Tristan Elliott
Tristan Elliott

Reputation: 922

Kotlin version for subscriptions

  • I have run into a similar problem but for subscriptions, so here is my solution.
  • If you ever have your user purchase a subscription, it is common to tell them when their next billing period is. Here is a simple Kotlin conversion:
                val timeStamp = purchase.purchaseTime
                val date = Date(timeStamp)
                val calendar = Calendar.getInstance()
                calendar.time = date
                calendar.add(Calendar.DATE,30)
                Timber.tag("TIMES").d(calendar.time.toString())
  • The purchase is a Purchase object. You should now be able to tell your user when their next billing period will be.

References

Upvotes: 0

ekholm
ekholm

Reputation: 2573

You are trying to parse a timestamp with SimpleDateFormat using an incorrect format string "MMddyyHHmmss". The timestamp value returned is expressed in "milliseconds since the epoch (Jan 1, 1970)". Parse the string to its long value and create a Date object directly from that:

Date date = new Date(Long.parseLong(timestampString)); 

Upvotes: 6

Related Questions