Get the customer's date, not the "SERVER" in C #

1

I am trying to capture the date of a client LOG IN on my portal. when using DateTime.Now I am capturing the time of the server, what I need is to obtain the time of my client, since the server is in a country where the schedule does not match the date and time of my client.

    
asked by Manu Keteimporta 12.07.2017 в 17:51
source

1 answer

3

Get the client's date with a server language? Impossible. You will have to generate it with javascript in the client and send it to the server.

You can use a input[hidden ] to save the client's date and send it:

var input = document.querySelector("#fecha_cliente");
var fechaCliente = new Date();
input.value = fechaCliente.getDay() + "/" + fechaCliente.getMonth() + 1 + "/" + fechaCliente.getFullYear();
<input type="text" name="fecha_cliente" id="fecha_cliente"/>

You just have to change the type text to hidden and ready.

Update:

Here is how to convert the date to System.DateTime when you receive it on the server:

 var dateParts = fecha_cliente.Split('/').Select(Int.Parse).ToArray();
 var fechaCliente = new DateTime(day: dateParts[0], month: dateParts[1], year:dateParts[2]);
    
answered by 12.07.2017 в 17:57