本文介绍了从字符串更改为double并完成减法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 如何从字符串更改为双倍并完成减法? localhour = Hidden1.Value.ToString UTChour = DateTime.UtcNow.ToString( HH) localTimeZone = CDbl (localhour) - CDbl (UTChour) Hidden1来自Javascript脚本: < ; script type = text / javascript > var localTime = new Date(); var hours = localTime.getHours(); document.getElementById(<% = Hidden1.ClientID %> )。价值=小时; < / script > < input id =Hidden1type =hiddenrunat =server/> 解决方案 0)不要对UtcNow进行ToString,只需访问Hour属性。 1)为什么要ToStringing Hidden1.Value?它是什么类型的? 2)你为什么要这样做?你想要获得UTC偏移吗? 这是我的解决方案: -JavaScript Code < script type = text / javascript > var localTime = new 日期(); var h = localTime.getHours(); document .getElementById( <% = Hidden1.ClientID%>)。value = h; < / script > -HTML < asp:hiddenfield id = Hidden1 value = 0 runat = server xmlns:asp = #unknown / > -Behind Code for C# string localHour = Hidden1.Value.ToString(); string UTChour = DateTime.UtcNow.ToString( HH); int diffTime = Convert.ToInt32(localHour) - Convert.ToInt32(UTChour); 希望它会对你有所帮助。 上帝保佑。 试试这个: 使用系统; public class 计划 { public static void Main() { int UTChour = DateTime.UtcNow.Hour; int localhour = DateTime.Now.Hour; int hourDiff = localhour - UTChour; Console.WriteLine(hourDiff); } } 参考更多: DateTime.UtcNow Property [ ^ ] How do you Change from string to double and complete the subtraction? localhour = Hidden1.Value.ToString UTChour = DateTime.UtcNow.ToString("HH") localTimeZone = CDbl(localhour) - CDbl(UTChour)Hidden1 is coming from a Javascript script: <script type="text/javascript"> var localTime = new Date(); var hours = localTime.getHours(); document.getElementById("<%=Hidden1.ClientID%>").value = hours; </script><input id="Hidden1" type="hidden" runat="server" /> 解决方案 0) Don't ToString the UtcNow, just access the Hour property.1) Why are you ToStringing Hidden1.Value ? What type is it?2) Why are you trying to do this? Are you trying to get the UTC offset?this is my solution:-JavaScript Code<script type="text/javascript"> var localTime = new Date(); var h = localTime.getHours(); document.getElementById("<%=Hidden1.ClientID%>").value = h;</script>-HTML<asp:hiddenfield id="Hidden1" value="0" runat="server" xmlns:asp="#unknown" />-Behind Code for C#string localHour = Hidden1.Value.ToString();string UTChour = DateTime.UtcNow.ToString("HH");int diffTime = Convert.ToInt32(localHour) - Convert.ToInt32(UTChour);Hope it will help you.,God Bless.Try this:using System;public class Program{ public static void Main() { int UTChour = DateTime.UtcNow.Hour; int localhour = DateTime.Now.Hour; int hourDiff = localhour - UTChour; Console.WriteLine(hourDiff); }}Refer more: DateTime.UtcNow Property[^] 这篇关于从字符串更改为double并完成减法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-24 08:53