I want to use German date formatting as default for my ASP.NET Core 2.2 application. On my Win10 machine with German language/layout it works, so I assumed that the timezone has to be set in my Dockerfile. According to the Alpine wiki, I did this:
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-alpine3.9 AS build-env
ENV TZ=Europe/Berlin
WORKDIR /app
COPY *.csproj ./
RUN dotnet restore
RUN apk add tzdata \
&& cp /usr/share/zoneinfo/${TZ} /etc/localtime \
&& echo "${TZ}" > /etc/timezone
COPY . ./
RUN dotnet publish -c Production -o dist
ENTRYPOINT ["dotnet", "./dist/MyApp.dll"]
According to the date
command, this worked:
/app # date
Sun Apr 7 13:50:42 CEST 2019
/app # date -u
Sun Apr 7 11:50:40 UTC 2019
But having a DateTime
object in my Model from the Database
<td>@article.PublishedTime.ToString("g")</td>
I get 4/7/19 12:16 AM
where my German Win10 machine shows 07.04.2019 00:16
. Why isn't this working? Since ASP.NET Core uses the system timezone, it should now use the 24h time format as set in linux.