Fill in date and time in View mvc 5 Razor

Asked

Viewed 501 times

3

I have a registration form where I have a record date field that I currently fill in my save method, only that my server is hosted in another country where the field is being filled in from the hosting location, quite different from where the system will run and the times do not match so I would like the help of how to take the time of the browser and pass in my form Submit, I believe that of to make via javascript or with the own Razor.

  • Specify in web.config the application’s regionality settings. Ex: <system.web><globalization culture="pt-BR" uiCulture="pt-BR"/></system.web>

1 answer

3


Javascript

With Javascript just use the new Date().

I did the example below by taking the date, formatting with the toLocaleString() and playing in an input text field.

var dataAtual = new Date();

$( document ).ready(function() {
    $("#campoData").val(dataAtual.toLocaleString())
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
Data de hoje: <input id="campoData" type="text">


C#

With C# you can use Timezone. Follows Example:

DateTime dataRussia = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, 
"Russian Standard Time");

If you want to see the Timezoneids list, you can do this:

foreach (TimeZoneInfo timeZone in TimeZoneInfo.GetSystemTimeZones())
{
    Console.WriteLine(timeZone .Id);
}

Below is the list of Timezone:

Dateline Standard Time

UTC-11

Samoa Standard Time

Hawaiian Standard Time

Alaskan Standard Time

Pacific Standard Time (Mexico)

Pacific Standard Time

US Mountain Standard Time

Mountain Standard Time (Mexico)

Mountain Standard Time

Central America Standard Time

Central Standard Time

Central Standard Time (Mexico)

Canada Central Standard Time

SA Pacific Standard Time

Eastern Standard Time

US Eastern Standard Time

Venezuela Standard Time

Paraguay Standard Time

Atlantic Standard Time

Central Brazilian Standard Time

SA Western Standard Time

Pacific SA Standard Time

Newfoundland Standard Time

E. South America Standard Time

Argentina Standard Time

SA Eastern Standard Time

Greenland Standard Time

Montevideo Standard Time

UTC-02

Mid-atlantic Standard Time

Azores Standard Time

Cape Verde Standard Time

Morocco Standard Time

UTC

GMT Standard Time

Greenwich Standard Time

W. Europe Standard Time

Central Europe Standard Time

Romance Standard Time

Central European Standard Time

W. Central Africa Standard Time

Namibia Standard Time

Jordan Standard Time

GTB Standard Time

Middle East Standard Time

Egypt Standard Time

Syria Standard Time

South Africa Standard Time

FLE Standard Time

Israel Standard Time

E. Europe Standard Time

Arabic Standard Time

Arab Standard Time

Russian Standard Time

E. Africa Standard Time

Iran Standard Time

Arabian Standard Time

Azerbaijan Standard Time

Mauritius Standard Time

Georgian Standard Time

Caucasus Standard Time

Afghanistan Standard Time

Ekaterinburg Standard Time

Pakistan Standard Time

West Asia Standard Time

India Standard Time

Sri Lanka Standard Time

Nepal Standard Time

Central Asia Standard Time

Bangladesh Standard Time

N. Central Asia Standard Time

Myanmar Standard Time

SE Asia Standard Time

North Asia Standard Time

China Standard Time

North Asia East Standard Time

Singapore Standard Time

W. Australia Standard Time

Taipei Standard Time

Ulaanbaatar Standard Time

Tokyo Standard Time

Korea Standard Time

Yakutsk Standard Time

Cen. Australia Standard Time

AUS Central Standard Time

E. Australia Standard Time

AUS Eastern Standard Time

West Pacific Standard Time

Tasmania Standard Time

Vladivostok Standard Time

Central Pacific Standard Time

New Zealand Standard Time

UTC+12

Fiji Standard Time

Kamchatka Standard Time

Tonga Standard Time

References:

  • 1

    Success! thank you very much. @George Wurthmann

Browser other questions tagged

You are not signed in. Login or sign up in order to post.