Reputation: 470
I am trying to retrive the subscription object data using nodejs into my project. Below is the subscription object. So whenever user signs up I want to store their subscription date and subscription next date. What I think is its
"current_period_end": 1613973928,
"current_period_start": 1611295528
But when I converted the time 1613973928 into Localstring it gives :
"Mon Jan 19 1970 21:49:33 GMT+0530 (India Standard Time)"
This is should be todays date.
{
"id": "sub_Inubyr5OJUppaI",
"object": "subscription",
"application_fee_percent": null,
"billing_cycle_anchor": 1611295528,
"billing_thresholds": null,
"cancel_at": null,
"cancel_at_period_end": false,
"canceled_at": null,
"collection_method": "charge_automatically",
"created": 1611295528,
"current_period_end": 1613973928,
"current_period_start": 1611295528,
"customer": "cus_InubUu9jTKtevF",
"days_until_due": null,
"default_payment_method": null,
"default_source": null,
"default_tax_rates": [],
"discount": null,
"ended_at": null,
"items": {
"object": "list",
"data": [
{
"id": "si_InubRpC6JA0U6W",
"object": "subscription_item",
"billing_thresholds": null,
"created": 1611295528,
"metadata": {},
"price": {
"id": "price_1Hvs1yGQ1LZjNPNJTN3wuIX0",
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1607379486,
"currency": "usd",
"livemode": false,
"lookup_key": null,
"metadata": {},
"nickname": null,
"product": "prod_IWvtx3h0tCJQ7c",
"recurring": {
"aggregate_usage": null,
"interval": "month",
"interval_count": 1,
"usage_type": "licensed"
},
"tiers_mode": null,
"transform_quantity": null,
"type": "recurring",
"unit_amount": 29900,
"unit_amount_decimal": "29900"
},
"quantity": 1,
"subscription": "sub_Inubyr5OJUppaI",
"tax_rates": []
}
],
"has_more": false,
"url": "/v1/subscription_items?subscription=sub_Inubyr5OJUppaI"
},
"latest_invoice": "in_1ICIlwGQ1LZjNPNJZGi0UDF0",
"livemode": false,
"metadata": {},
"next_pending_invoice_item_invoice": null,
"pause_collection": null,
"pending_invoice_item_interval": null,
"pending_setup_intent": null,
"pending_update": null,
"schedule": null,
"start_date": 1611295528,
"status": "active",
"transfer_data": null,
"trial_end": null,
"trial_start": null
}
Upvotes: 1
Views: 790
Reputation: 2906
Unix timestamps are in seconds, but JS works in milliseconds:
new Date(1613973928 * 1000).toLocaleDateString()
// '2/22/2021'
Upvotes: 1