# How to change date format?

**URL:** <https://forum.gitea.com/t/how-to-change-date-format/2099>\
**Category:** General\
**Created:** [April 20, 2020, 10:08am UTC](https://forum.gitea.com/t/how-to-change-date-format/2099 "2020-04-20T10:08:00Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![bugblatterbeast](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bugblatterbeast](https://forum.gitea.com/u/bugblatterbeast)\
**Post date:** [April 20, 2020, 10:08am UTC](https://forum.gitea.com/t/how-to-change-date-format/2099/1 "2020-04-20T10:08:00Z")

</div>

Everything’s great except one thing: the date format. I just can’t work with “3 month ago”. I don’t want to hover over each item to see the actual date. I need to change all date output (issues, commits, wiki-page-edits, …) to absolute format. How would I do that?

---

<div class="post-metadata">

**Author:** ![jolheiser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/jolheiser/32/4807_2.png) [@jolheiser](https://forum.gitea.com/u/jolheiser)\
**Post date:** [May 6, 2020, 2:31pm UTC](https://forum.gitea.com/t/how-to-change-date-format/2099/2 "2020-05-06T14:31:51Z")

</div>

Unfortunately I believe this would require changes in a large number of templates. That string is created in the template and then displayed ([example](https://github.com/go-gitea/gitea/blob/505e456f26e11d4ee2f7a807a037b11b59defb1f/templates/repo/issue/view_content/comments.tmpl#L3))

---

<div class="post-metadata">

**Author:** ![bugblatterbeast](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bugblatterbeast](https://forum.gitea.com/u/bugblatterbeast)\
**Post date:** [May 6, 2020, 3:48pm UTC](https://forum.gitea.com/t/how-to-change-date-format/2099/3 "2020-05-06T15:48:46Z")

</div>

Thank you very much for the reply. I need to change that, no matter how many files I have to change. I really want to keep using gitea but this date format is unbearable.

Could I please bother you to go a bit more into detail? Right now, I don’t see where the output I am looking for could be generated in the source you’ve linked. I fail to see how that file could be changed to generate the desired output format (at least for some elements).

Here’s an example of the current output:

`<span class="time-since poping up visible" title="" data-content="Wed, 22 Apr 2020 15:30:39 CEST" data-variation="inverted tiny">2 weeks ago</span>`

As you can see, in the attribute data-content already holds the value in a much preferable format.

In the source code you’ve linked in your reply the line  
`{{ $createdStr:= TimeSinceUnix .CreatedUnix $.Lang }}`  
does look kinda promising. Additionally it would be very interesting, what all those lines do, that look like this:  
`{{$.i18n.Tr "repo.issues.reopened_at" .EventTag $createdStr | Safe}}`  
still I can’t make much out of it. I am guessing that $.i18n.Tr points to the translation function.

---

<div class="post-metadata">

**Author:** ![jolheiser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/jolheiser/32/4807_2.png) [@jolheiser](https://forum.gitea.com/u/jolheiser)\
**Post date:** [May 14, 2020, 5:56pm UTC](https://forum.gitea.com/t/how-to-change-date-format/2099/4 "2020-05-14T17:56:31Z")

</div>

After looking into it more, it seems this is all determined in the backend.

> <https://github.com/go-gitea/gitea/blob/171b3598778a1ecd0a921c71ed6755bfef68f7f0/modules/timeutil/since.go#L144-L164>

Note that the format you prefer is actually placed in the `title` attribute, however when the JS transforms it, it is moved to `data-content`

I believe in order to get what you want, you may have to change the source code itself, or put an issue in on GitHub and someone may pick it up to allow customizing that output.

---

<div class="post-metadata">

**Author:** ![bugblatterbeast](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bugblatterbeast](https://forum.gitea.com/u/bugblatterbeast)\
**Post date:** [March 6, 2021, 1:23pm UTC](https://forum.gitea.com/t/how-to-change-date-format/2099/5 "2021-03-06T13:23:14Z")

</div>

Thank you very much for your reply jolheiser, sorry for the late answer.

I do not have any experience with the go language. Sadly I don’t have the time to get into the language and try to adjust the code myself. I do not know go syntax and I haven’t spent much time analysing the template mechanics. Still, in the line of code you’ve posted on your first reply

{{ createdStr:= TimeSinceUnix .CreatedUnix .Lang }}

> <https://github.com/go-gitea/gitea/blob/505e456f26e11d4ee2f7a807a037b11b59defb1f/templates/repo/issue/view_content/comments.tmpl#L3>

it looks like “TimeSinceUnix” is a function call (I’m just guessing) and “.CreatedUnix” and “$.Lang” are it’s arguments. Wouldn’t it be possible to fill the variable “$createdStr” with the result of another function in that place? Would it be possible to call some basic time-to-string function or am I completely wrong here?

“// TimeSinceUnix calculates the time interval and generate user-friendly string.”

> <https://github.com/go-gitea/gitea/blob/171b3598778a1ecd0a921c71ed6755bfef68f7f0/modules/timeutil/since.go#L155>

It’s so beyond me how anybody could think that this would be user friendly. Just now I need to prepare a detailed activity report for a funding body that also has to cover the time when we were using just gitea (we started using an additional project management software that’s why the issue didn’t bother me lately). How should it help me when I look at the list of issues and every entry says “one year ago”???

Seriously, how is it possible that nobody else but me is driven crazy because of this “user-friendly” date format? How should anybody be able to create management reports from this? I admit that it might be kinda nice when you’re dealing with the current day or maybe the current week but that’s all.

Kind regards

---

<div class="post-metadata">

**Author:** ![bugblatterbeast](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bugblatterbeast](https://forum.gitea.com/u/bugblatterbeast)\
**Post date:** [March 6, 2021, 2:35pm UTC](https://forum.gitea.com/t/how-to-change-date-format/2099/6 "2021-03-06T14:35:41Z")

</div>

Changing the line

{{ createdStr:= TimeSinceUnix .CreatedUnix .Lang }}

to

{{ $createdStr:= .CreatedUnix.Format “am 02.01.2006 um 15:04:05 Uhr” }}  
edit: removed link to gitea source code here /edit

Fixed the issue for me. So far only for the comments.

I had to use a function of the class timeutil and I had to hard code the German data format. But that’s fine with me for now.

Now I have to find all templates calling the function TimeSinceUnix and apply the same change there.

Kind regards

---

<div class="post-metadata">

**Author:** ![bugblatterbeast](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bugblatterbeast](https://forum.gitea.com/u/bugblatterbeast)\
**Post date:** [March 6, 2021, 6:06pm UTC](https://forum.gitea.com/t/how-to-change-date-format/2099/7 "2021-03-06T18:06:48Z")

</div>

Where do I find correct template?

I’m using the most current version of gitea.  
Gitea version 1.13.3 built with GNU Make 4.1, go1.15.8 : bindata, sqlite, sqlite\_unlock\_notify

I’ve downloaded templates from github go-gitea/gitea (posting link to that host is not allowed here)

I can’t start gitea because those templates contain unkown functions

gitea[10864]: panic: template: shared/issuelist:130: function “avatar” not defined  
gitea[11214]: panic: template: user/dashboard/feeds:4: function “avatarByAction” not defined  
gitea[11561]: panic: template: user/dashboard/feeds:95: function “avatarHTML” not defined

what am I doing wrong here?

---

<div class="post-metadata">

**Author:** ![bugblatterbeast](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bugblatterbeast](https://forum.gitea.com/u/bugblatterbeast)\
**Post date:** [March 6, 2021, 6:11pm UTC](https://forum.gitea.com/t/how-to-change-date-format/2099/8 "2021-03-06T18:11:38Z")

</div>

please reconsider flagging previous posts as spam. that is completely uncalled for. I’d understand if you’d say one of those post was controversial but I don’t see a reason to mark it as spam.

kind regards

---

<div class="post-metadata">

**Author:** ![bugblatterbeast](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bugblatterbeast](https://forum.gitea.com/u/bugblatterbeast)\
**Post date:** [March 7, 2021, 1:24am UTC](https://forum.gitea.com/t/how-to-change-date-format/2099/9 "2021-03-07T01:24:31Z")

</div>

> [@bugblatterbeast](#):
>
> what am I doing wrong here?

I was sure I checked out the right branch but obviously didn’t. I was still on master. Of course the templates worked just fine once I sucessfully switched to release/v1.13

I’ve copied the following templates:  
./admin/monitor.tmpl  
./user/dashboard/issues.tmpl  
./user/dashboard/milestones.tmpl  
./user/dashboard/feeds.tmpl  
./repo/branch/list.tmpl  
./repo/wiki/pages.tmpl  
./repo/wiki/view.tmpl  
./repo/wiki/revision.tmpl  
./repo/projects/list.tmpl  
./repo/issue/milestone\_issues.tmpl  
./repo/issue/list.tmpl  
./repo/issue/view\_content/pull.tmpl  
./repo/issue/view\_content/comments.tmpl  
./repo/issue/view\_title.tmpl  
./repo/issue/milestones.tmpl  
./repo/issue/view\_content.tmpl  
./repo/activity.tmpl  
./repo/commit\_page.tmpl  
./repo/diff/comments.tmpl  
./repo/settings/lfs\_locks.tmpl  
./repo/settings/lfs\_file\_find.tmpl  
./repo/settings/lfs.tmpl  
./repo/release/list.tmpl  
./repo/commits\_list.tmpl  
./repo/search.tmpl  
./repo/view\_list.tmpl  
./explore/repo\_list.tmpl  
./explore/code.tmpl

Then I used this shell command to change all the calls to either TimeSince or TimeSinceUnix on the copied templates:  
`find . -type f -exec sed -i 's/TimeSince[A-Za-z]*\ \([\$\.A-Za-z0-9]*\)\ [\$\.A-Za-z0-9]*/\1.Format "am 02.01.2006 um 15:04:05 Uhr"/g' {} +`

As mentioned before, I didn’t find a way around using a hard coded date format.

This solved the issue for me.

---

<div class="post-metadata">

**Author:** ![cpbr](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/cpbr/32/1192_2.png) [@cpbr](https://forum.gitea.com/u/cpbr)\
**Post date:** [March 8, 2021, 11:15pm UTC](https://forum.gitea.com/t/how-to-change-date-format/2099/10 "2021-03-08T23:15:16Z")

</div>

You can actually switch to absolute dates entirely in the browser by adding a bookmarklet with the following function:

`javascript:function datestamp(){for (elem of $('span.time-since')) {elem.textContent = elem.attributes["data-content"].value };} datestamp();`

You do have to click it every time, but it doesn’t require a code/template change.

---

<div class="post-metadata">

**Author:** ![bugblatterbeast](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bugblatterbeast](https://forum.gitea.com/u/bugblatterbeast)\
**Post date:** [March 9, 2021, 1:03am UTC](https://forum.gitea.com/t/how-to-change-date-format/2099/11 "2021-03-09T01:03:29Z")

</div>

Oh, if only I knew. That would have spared me a lot of trouble.

Still, thank you very much for the info.

> [@cpbr](#):
>
> You do have to click it every time, but it doesn’t require a code/template change.

Would it be possible to make it permanent with a tool like tampermonkey for example?

---

<div class="post-metadata">

**Author:** ![FabioTavernini](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/fabiotavernini/32/4328_2.png) [@FabioTavernini](https://forum.gitea.com/u/FabioTavernini)\
**Post date:** [January 10, 2024, 10:26am UTC](https://forum.gitea.com/t/how-to-change-date-format/2099/12 "2024-01-10T10:26:25Z")

</div>

Hey there, im just replying for future generations:  
I solved exaclty this problem by adding a script tag to my header.tmpl file:

```auto
<script>
document.addEventListener("DOMContentLoaded", function(event) { 
 var times = document.getElementsByClassName("time-since");
 for (var i = 0; i < times.length; i++) {
   times.item(i).shadowRoot.firstChild.textContent = times.item(i).innerHTML.slice(0, -7);
 }
});
</script>

```

Maybe this will help others 😃

---

<div class="post-metadata">

**Author:** ![remram44](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/remram44/32/3152_2.png) [@remram44](https://forum.gitea.com/u/remram44)\
**Post date:** [February 18, 2024, 3:46am UTC](https://forum.gitea.com/t/how-to-change-date-format/2099/13 "2024-02-18T03:46:40Z")

</div>

Looks like this was just added as a config option recently (after 1.22.0), so it will be available in the next release: [Add global setting how timestamps should be rendered by yardenshoham · Pull Request #28657 · go-gitea/gitea · GitHub](https://github.com/go-gitea/gitea/pull/28657)
