Output of time formatter is incorrect
I am trying to format time using time Format function as MMM dd yyyy, HH:mm:ss format but getting incorrect date as output. Below is the code for reference
package main
import (
"fmt"
"time"
)
func main() {
var t time.Time
t = time.Now()
fmt.Println(t.Format("Jan 01 2006, 15:04:05"))
//Output
//Dec 12 2018, 16:27:34
}
But if I change the reference format as Jan 02 2006, 15:04:05
I get a correct output. So I am not able to find what is the issue between two dates reference and what would be the correct reference date format which works in all use case.
go
add a comment |
I am trying to format time using time Format function as MMM dd yyyy, HH:mm:ss format but getting incorrect date as output. Below is the code for reference
package main
import (
"fmt"
"time"
)
func main() {
var t time.Time
t = time.Now()
fmt.Println(t.Format("Jan 01 2006, 15:04:05"))
//Output
//Dec 12 2018, 16:27:34
}
But if I change the reference format as Jan 02 2006, 15:04:05
I get a correct output. So I am not able to find what is the issue between two dates reference and what would be the correct reference date format which works in all use case.
go
1
You get correct output when you pass correct input. It's all covered in the documentation: golang.org/pkg/time/#example_Time_Format
– Adrian
Dec 31 '18 at 14:27
add a comment |
I am trying to format time using time Format function as MMM dd yyyy, HH:mm:ss format but getting incorrect date as output. Below is the code for reference
package main
import (
"fmt"
"time"
)
func main() {
var t time.Time
t = time.Now()
fmt.Println(t.Format("Jan 01 2006, 15:04:05"))
//Output
//Dec 12 2018, 16:27:34
}
But if I change the reference format as Jan 02 2006, 15:04:05
I get a correct output. So I am not able to find what is the issue between two dates reference and what would be the correct reference date format which works in all use case.
go
I am trying to format time using time Format function as MMM dd yyyy, HH:mm:ss format but getting incorrect date as output. Below is the code for reference
package main
import (
"fmt"
"time"
)
func main() {
var t time.Time
t = time.Now()
fmt.Println(t.Format("Jan 01 2006, 15:04:05"))
//Output
//Dec 12 2018, 16:27:34
}
But if I change the reference format as Jan 02 2006, 15:04:05
I get a correct output. So I am not able to find what is the issue between two dates reference and what would be the correct reference date format which works in all use case.
go
go
edited Dec 31 '18 at 11:00
Abhinav
asked Dec 31 '18 at 6:57
AbhinavAbhinav
3161521
3161521
1
You get correct output when you pass correct input. It's all covered in the documentation: golang.org/pkg/time/#example_Time_Format
– Adrian
Dec 31 '18 at 14:27
add a comment |
1
You get correct output when you pass correct input. It's all covered in the documentation: golang.org/pkg/time/#example_Time_Format
– Adrian
Dec 31 '18 at 14:27
1
1
You get correct output when you pass correct input. It's all covered in the documentation: golang.org/pkg/time/#example_Time_Format
– Adrian
Dec 31 '18 at 14:27
You get correct output when you pass correct input. It's all covered in the documentation: golang.org/pkg/time/#example_Time_Format
– Adrian
Dec 31 '18 at 14:27
add a comment |
1 Answer
1
active
oldest
votes
Layouts must use the reference time Mon Jan 2 15:04:05 MST 2006 to
show the pattern with which to format/parse a given time/string.
Source: https://gobyexample.com/time-formatting-parsing
If you really want to understand this fully, dig into the source.
If you really want to understand this fully, read the packagetime
documentation: golang.org/pkg/time
– peterSO
Dec 31 '18 at 14:30
The comments are the same as in the source ;)
– maio290
Dec 31 '18 at 14:31
First, read the documentation. Then, if necessary, read the source. By design, unformatted documentation is included in the source.
– peterSO
Dec 31 '18 at 14:32
I'm not going to discuss with you what kind of information someone has to prefer since that's down to a personal taste. However, I think the source code is always a more detailed documentation than any documentation can ever be. Since the reason for the behaviour can be found in it. But that's just my point of view and there is no wrong or correct here.
– maio290
Dec 31 '18 at 16:54
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53984528%2foutput-of-time-formatter-is-incorrect%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Layouts must use the reference time Mon Jan 2 15:04:05 MST 2006 to
show the pattern with which to format/parse a given time/string.
Source: https://gobyexample.com/time-formatting-parsing
If you really want to understand this fully, dig into the source.
If you really want to understand this fully, read the packagetime
documentation: golang.org/pkg/time
– peterSO
Dec 31 '18 at 14:30
The comments are the same as in the source ;)
– maio290
Dec 31 '18 at 14:31
First, read the documentation. Then, if necessary, read the source. By design, unformatted documentation is included in the source.
– peterSO
Dec 31 '18 at 14:32
I'm not going to discuss with you what kind of information someone has to prefer since that's down to a personal taste. However, I think the source code is always a more detailed documentation than any documentation can ever be. Since the reason for the behaviour can be found in it. But that's just my point of view and there is no wrong or correct here.
– maio290
Dec 31 '18 at 16:54
add a comment |
Layouts must use the reference time Mon Jan 2 15:04:05 MST 2006 to
show the pattern with which to format/parse a given time/string.
Source: https://gobyexample.com/time-formatting-parsing
If you really want to understand this fully, dig into the source.
If you really want to understand this fully, read the packagetime
documentation: golang.org/pkg/time
– peterSO
Dec 31 '18 at 14:30
The comments are the same as in the source ;)
– maio290
Dec 31 '18 at 14:31
First, read the documentation. Then, if necessary, read the source. By design, unformatted documentation is included in the source.
– peterSO
Dec 31 '18 at 14:32
I'm not going to discuss with you what kind of information someone has to prefer since that's down to a personal taste. However, I think the source code is always a more detailed documentation than any documentation can ever be. Since the reason for the behaviour can be found in it. But that's just my point of view and there is no wrong or correct here.
– maio290
Dec 31 '18 at 16:54
add a comment |
Layouts must use the reference time Mon Jan 2 15:04:05 MST 2006 to
show the pattern with which to format/parse a given time/string.
Source: https://gobyexample.com/time-formatting-parsing
If you really want to understand this fully, dig into the source.
Layouts must use the reference time Mon Jan 2 15:04:05 MST 2006 to
show the pattern with which to format/parse a given time/string.
Source: https://gobyexample.com/time-formatting-parsing
If you really want to understand this fully, dig into the source.
edited Dec 31 '18 at 11:19
answered Dec 31 '18 at 11:05
maio290maio290
2,014414
2,014414
If you really want to understand this fully, read the packagetime
documentation: golang.org/pkg/time
– peterSO
Dec 31 '18 at 14:30
The comments are the same as in the source ;)
– maio290
Dec 31 '18 at 14:31
First, read the documentation. Then, if necessary, read the source. By design, unformatted documentation is included in the source.
– peterSO
Dec 31 '18 at 14:32
I'm not going to discuss with you what kind of information someone has to prefer since that's down to a personal taste. However, I think the source code is always a more detailed documentation than any documentation can ever be. Since the reason for the behaviour can be found in it. But that's just my point of view and there is no wrong or correct here.
– maio290
Dec 31 '18 at 16:54
add a comment |
If you really want to understand this fully, read the packagetime
documentation: golang.org/pkg/time
– peterSO
Dec 31 '18 at 14:30
The comments are the same as in the source ;)
– maio290
Dec 31 '18 at 14:31
First, read the documentation. Then, if necessary, read the source. By design, unformatted documentation is included in the source.
– peterSO
Dec 31 '18 at 14:32
I'm not going to discuss with you what kind of information someone has to prefer since that's down to a personal taste. However, I think the source code is always a more detailed documentation than any documentation can ever be. Since the reason for the behaviour can be found in it. But that's just my point of view and there is no wrong or correct here.
– maio290
Dec 31 '18 at 16:54
If you really want to understand this fully, read the package
time
documentation: golang.org/pkg/time– peterSO
Dec 31 '18 at 14:30
If you really want to understand this fully, read the package
time
documentation: golang.org/pkg/time– peterSO
Dec 31 '18 at 14:30
The comments are the same as in the source ;)
– maio290
Dec 31 '18 at 14:31
The comments are the same as in the source ;)
– maio290
Dec 31 '18 at 14:31
First, read the documentation. Then, if necessary, read the source. By design, unformatted documentation is included in the source.
– peterSO
Dec 31 '18 at 14:32
First, read the documentation. Then, if necessary, read the source. By design, unformatted documentation is included in the source.
– peterSO
Dec 31 '18 at 14:32
I'm not going to discuss with you what kind of information someone has to prefer since that's down to a personal taste. However, I think the source code is always a more detailed documentation than any documentation can ever be. Since the reason for the behaviour can be found in it. But that's just my point of view and there is no wrong or correct here.
– maio290
Dec 31 '18 at 16:54
I'm not going to discuss with you what kind of information someone has to prefer since that's down to a personal taste. However, I think the source code is always a more detailed documentation than any documentation can ever be. Since the reason for the behaviour can be found in it. But that's just my point of view and there is no wrong or correct here.
– maio290
Dec 31 '18 at 16:54
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53984528%2foutput-of-time-formatter-is-incorrect%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You get correct output when you pass correct input. It's all covered in the documentation: golang.org/pkg/time/#example_Time_Format
– Adrian
Dec 31 '18 at 14:27