Output of time formatter is incorrect












-2















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.










share|improve this question




















  • 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
















-2















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.










share|improve this question




















  • 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














-2












-2








-2








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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












1 Answer
1






active

oldest

votes


















1















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.






share|improve this answer


























  • 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











  • 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











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
});


}
});














draft saved

draft discarded


















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









1















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.






share|improve this answer


























  • 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











  • 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
















1















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.






share|improve this answer


























  • 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











  • 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














1












1








1








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.






share|improve this answer
















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.







share|improve this answer














share|improve this answer



share|improve this answer








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 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











  • 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













  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas