Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Date#getHours() return hour + 1?

This is my code:

var feedDataTimestamp = new Date("2014-01-14T00:04:40+0000").getTime();
var parsedDate = new Date(+feedDataTimestamp);
alert(parsedDate.getHours());

but it should print 0, not 1: time is 00:04:40

like image 496
markzzz Avatar asked Jan 15 '14 10:01

markzzz


People also ask

What does dates do to the female body?

Dates are an excellent source of vitamin C and D which helps to maintain your skin elasticity and keeps your skin smooth. Dates also come with anti-ageing properties and prevent the accumulation of melanin.

What does date do to your body?

Dates are a source of bone-friendly minerals including phosphorus, potassium, calcium and magnesium. They are also a source of vitamin K which is needed for healthy, strong bones.

Does date increase sperm count?

“Eating dates will promote sperm quality and quantity as it is one of the best natural fruits used for male fertility. “It also increases the size of testes in men and the size of breast in women. “Consuming the fruit can help to treat sexual disorders because it is a natural aphrodisiac.”

Why do we use dates?

They are high in several nutrients, fiber and antioxidants, all of which may provide health benefits ranging from improved digestion to a reduced risk of disease. There are several ways to add dates to your diet. One popular way to eat them is as a natural sweetener in various dishes. They also make a great snack.


2 Answers

Because you (according to your Stackoverflow profile) are in Italy, so your time zone is UTC+1.

The time stamp you are inputting is UTC+0.

parsedDate will be in local time.

Use the getUTCHours() method if you want to get UTC time instead of local time.

like image 191
Quentin Avatar answered Sep 18 '22 10:09

Quentin


You set the timezone in the parsed string as +0000 so you seem to want the hours in UTC, use

alert(parsedDate.getUTCHours())
like image 43
Denys Séguret Avatar answered Sep 19 '22 10:09

Denys Séguret