# Sugar.DateTime constructor bug

**URL:** https://talk.remobjects.com/t/sugar-datetime-constructor-bug/9333
**Category:** Elements RTL
**Created:** [May 10, 2016, 12:41pm UTC](https://talk.remobjects.com/t/sugar-datetime-constructor-bug/9333 "2016-05-10T12:41:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Koen\_Kraak](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/k/3bc359/32.png) [@Koen\_Kraak](https://talk.remobjects.com/u/Koen_Kraak)
#### Post date: [May 10, 2016, 12:41pm UTC](https://talk.remobjects.com/t/sugar-datetime-constructor-bug/9333/1 "2016-05-10T12:41:34Z")

</div>

When initializing a DateTime and printing it results in the wrong time being printed:

You can reproduce it by executing the following code:

```
print("Time = \(Sugar.DateTime(2000, 2, 14, 0, 0, 0).ToString())")

```

The output is:  
Time = 14/02/2000 12:00:00

And the expected output is:  
Time = 14/02/2000 00:00:00

How come 0 is seen as 12? When passing 1 the hour is displayed correctly

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [May 10, 2016, 12:57pm UTC](https://talk.remobjects.com/t/sugar-datetime-constructor-bug/9333/2 "2016-05-10T12:57:04Z")

</div>

Could this simply be a 12 vs 24h display issue? Where 12:00 am is printed as 0:00? What locale are you on, and what platform does the shape with — .NET, Cocoa or Java?

---

<div class="post-metadata">

### Author: ![Koen\_Kraak](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/k/3bc359/32.png) [@Koen\_Kraak](https://talk.remobjects.com/u/Koen_Kraak)
#### Post date: [May 11, 2016, 7:53am UTC](https://talk.remobjects.com/t/sugar-datetime-constructor-bug/9333/3 "2016-05-11T07:53:44Z")

</div>

Well the issue is not that 12.00 is printed as 0:00. It’s the other way around. hour 0 is printed as 12:00 and hour 1 is printed as 01:00. Locale is GMT + 1 and this issue is on Android.

But it’s probably just something in the ToString method causing this behaviour. Since hours:

- 0
- 12
- 24

are all printed as 12:00

and hour 23 is printed as 11:00 instead of 23:00.

So I guess the easiest way to work around this is using the getHour() method in a own Formatter since this results in the following:

- 0 results in 0
- 24 results in 0
- 12 results in 12

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [May 11, 2016, 11:13am UTC](https://talk.remobjects.com/t/sugar-datetime-constructor-bug/9333/4 "2016-05-11T11:13:12Z")

</div>

> [@Koen\_Kraak](#):
>
> Since hours: - 0- 12- 24

Right. That’s just how the 12-h time system prints time?
