Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Javascript time string to DateTime or TimeSpan in MVC Controller

How do I covert JavaScript string "5:00 PM" to DateTime or TimeSpan when it get send to the MVC controller. I am using

bootstrap-timepicker

 // usage      
 <script type="text/javascript">
        $('#timepicker1').timepicker();
 </script>

Javascript payload

{
  Skip: 0
  Status: []
  Take: 15
  DueTime: "1:00 PM" // keep in mind that this is a string
}

Server Object would be something like

class TimeSheet
{
   public TimeSpan DueTime;
}
like image 828
eugenekgn Avatar asked Nov 02 '22 06:11

eugenekgn


1 Answers

Use DateTime.Parse. Convert on server(on controller) when your string would transmit with your time. http://msdn.microsoft.com/ru-ru/library/system.datetime.parse(v=vs.110).aspx

like image 98
Vlad Dekhanov Avatar answered Nov 13 '22 15:11

Vlad Dekhanov