在IIS(远程系统)上部署应用程序后,转换为日期不起作用

时间:2018-06-13 05:35:23

标签: jquery vb.net date iis

我正在调用一个从java脚本编写VB.NET n的Web方法,在Visual Studio上工作时效果很好。

Public Shared Function MyServiceRequest(ByVal Type As String, ByVal StartDateTime As String, ByVal EndDateTime As String,
   ByVal Sites() As String, ByVal Areas() As String,
   ByVal Eqs As String, ByVal Units() As String, ByVal Plants As String,
   ByVal Conformance() As String) As Object
  Dim SQLCon As New SqlClient.SqlConnection
  Dim SQLCmd As New SqlClient.SqlCommand
  Dim SQLReader As SqlClient.SqlDataReader
  Dim SQLSPCall As String



  Dim serializer As New JavaScriptSerializer()
  Dim JsonOut As String

  Dim StartTime As DateTime
  Dim EndTime As DateTime
  Dim SpResult As Integer
  Dim ReturnMessage As String = ""


  //Errors here
  StartTime = CType(StartDateTime, DateTime)
  EndTime = CType(EndDateTime, DateTime)


  --Other Code
End Function

然后我收到错误:

  

{"消息":"转换自字符串\" 30/05/2018 03:22 PM \"至   键入\ u0027Date \ u0027无效。"," StackTrace":"
   在Microsoft.VisualBasic.CompilerServices.Conversions.ToDate(String Value)\ r \ n at    在C:\ Data中的TestApp.CIP.MyServiceRequest(String Type,String StartDateTime,String EndDateTime,String [] Sites,String [] Areas,String [] Sets,String [] Circuits,String [] Wash,String [] Conformance) \ Projects \ TestApp \ App.aspx.vb:第109行"," ExceptionType":" System.InvalidCastException"}

什么错了?如果日期字符串格式错误,它也应该在visual studio dev服务器上出错!!

2 个答案:

答案 0 :(得分:1)

根据评论中的讨论 在配置文件中添加此设置解决了问题。

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<div class="container">
<div class="card" style="width:400px">
<div class="row">
  <div class="col-sm-6">
    <img class="card-img" src="https://material.angular.io/assets/img/examples/shiba1.jpg" alt="Card image"/>
  </div>
  <div class="col-sm-6">
    <div class="card-body-right">
      <h4 class="card-title">John Doe</h4>
      <p class="card-text">Some example text some example text. John Doe is an architect and engineer</p>
      <a href="#" class="btn btn-primary">See Profile</a>
    </div>
     </div>
  </div> 
  </div>
</div>

答案 1 :(得分:0)

Dim DateTimeFix As DateTime 'Fix time format (Example: 2010-12-31 14:60:60)
DateTime.TryParseExact(TimeToFix, "yyyy-MM-dd HH:mm:ss", Globalization.DateTimeFormatInfo.InvariantInfo, Globalization.DateTimeStyles.None, DateTimeFix)
TimeToFix = DateTimeFix.ToString("HH:mm, dd MMM yyyy")' or whatever format you like