字符串转换为datetime vb.net [英] convert string to datetime vb.net

查看:696
本文介绍了字符串转换为datetime vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要字符串转换为日期格式。要求是如果选择当前月份,日期应该是GETDATE。如果选择任何其他月份则应该是:第一,一个月的。 数据进来的是2010年1月,2010年2月等。 但应插入到SQL Server数据库作为01/01/10 02/01/10或

i need to convert strings to date format. the requirement is if current month is selected, the date should be getdate. if any other month is selected then it should be first of that month. the data coming in is "January 2010", "February 2010" and so on. but it should be inserted into sql server database as 01/01/10 or 02/01/10

推荐答案

我认为下面应该做的工作适合你:

I think the following should do the job for you:

Dim theDate As DateTime = DateTime.ParseExact(input, "MMMM yyyy", CultureInfo.InvariantCulture)

InvariantCulture的可确保月份名称可以正确地进行解析。

The InvariantCulture makes sure that the month names can be parsed correctly.

这篇关于字符串转换为datetime vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆