1
votes

i'm able to show the "default" date with this format: Thu Jan 01 1970 01:01:00 GMT+0100

And i want to get this format: Thursday, 09 Jan 2017 06:00

Code i have so far: (Not written by me)

var date = new Date(customData[0].timestamp*1000);
// Hours part from the timestamp
var hours = date.getHours();
// Minutes part from the timestamp
var minutes = "0" + date.getMinutes();
// Seconds part from the timestamp
var seconds = "0" + date.getSeconds();
// Will display time in 10:30:23 format
var formattedTime = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);

If i call the variable "date":

Thu Jan 01 1970 01:01:00 GMT+0100

If i call the variable "formattedDate":

0:00:00

I call the variable using:

<Text style={textStyles.text_dies_mostrats}>{formattedTime.toString()}</Text>

Any ideas?

1
Easier, take a look at moment.js - Facundo La Rocca
Your code works fine if you use just new Date() so I suspect there is some problem with your custom data, could you print just customData[0].timestamp? - Facundo La Rocca
customData is data from a JSON file, and the value of customData[0].timestamp is: 1488150000 - Roger Mimó
It is working fine, take a look here - Facundo La Rocca
Could customData[0].timestamp be coming null or undefined? - Facundo La Rocca

1 Answers

0
votes

I made a lab here and your code is working fine.

I suspect that timestamp is coming null or undefined, or the time it is showing is the time it should show.

But your code seems to be working fine.