求帮我vb.net代码转成c#

'''<summary>'''日付作成'''</summary>'''<paramname="str"></param>'''<returns></returns>'''... ''' <summary>
''' 日付作成
''' </summary>
''' <param name="str"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function CreateDate(ByRef str As String) As Boolean

If (String.IsNullOrEmpty(str)) Then
Return False
End If

Dim int_ As Int32 = 0
If Not Int32.TryParse(str, int_) Then
Return False
End If

Dim dateStr As String = str
Dim inYear As String
Dim inMonth As String
Dim inDay As String

'现在の日付を取得
Dim nowdate As String = Format(Now(), "yyyyMMdd")
'年を取得
Dim year As String = nowdate.Substring(0, 4)
'月を取得
Dim month As String = nowdate.Substring(4, 2)

Select Case dateStr.Length
Case 8
'8桁(YYYYMMDD)の场合
inYear = dateStr.Substring(0, 4)
inMonth = dateStr.Substring(4, 2)
inDay = dateStr.Substring(6, 2)
Exit Select
Case 6
'6桁(YYMMDD)の场合
inYear = year.Substring(0, 2) + dateStr.Substring(0, 2)
inMonth = dateStr.Substring(2, 2)
inDay = dateStr.Substring(4, 2)
Exit Select
Case 4
'4桁(MMDD)の场合
inYear = year
inMonth = dateStr.Substring(0, 2)
inDay = dateStr.Substring(2, 2)
Exit Select
Case 3
'3桁(MDD)の场合
inYear = year
inMonth = "0" + dateStr.Substring(0, 1)
inDay = dateStr.Substring(1, 2)
Exit Select
Case 2
'2桁(DD)の场合
inYear = year
inMonth = month
inDay = dateStr.Substring(0, 2)
Exit Select
Case 1
'1桁(D)の场合
inYear = year
inMonth = month
inDay = "0" + dateStr.Substring(0, 1)
Exit Select
Case Else
'それ以外の桁がきた场合はエラー
Return False
End Select
'日付チェック
If IsDate(convertSlash(inYear + inMonth + inDay)) Then
str = inYear + inMonth + inDay
Else
Return False
End If

Return True
End Function
展开
 我来答
般木鲸家15
2010-02-10
知道答主
回答量:27
采纳率:0%
帮助的人:17.4万
展开全部
/// <summary>
/// 日付作成
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
/// <remarks></remarks>
public static bool CreateDate(ref string str)
{

if ((string.IsNullOrEmpty(str))) {
return false;
}

Int32 int_ = 0;
if (!Int32.TryParse(str, int_)) {
return false;
}

string dateStr = str;
string inYear = null;
string inMonth = null;
string inDay = null;

//现在の日付を取得
string nowdate = Strings.Format(Now(), "yyyyMMdd");
//年を取得
string year = nowdate.Substring(0, 4);
//月を取得
string month = nowdate.Substring(4, 2);

switch (dateStr.Length) {
case 8:
//8桁(YYYYMMDD)の场合
inYear = dateStr.Substring(0, 4);
inMonth = dateStr.Substring(4, 2);
inDay = dateStr.Substring(6, 2);
break; // TODO: might not be correct. Was : Exit Select

break;
case 6:
//6桁(YYMMDD)の场合
inYear = year.Substring(0, 2) + dateStr.Substring(0, 2);
inMonth = dateStr.Substring(2, 2);
inDay = dateStr.Substring(4, 2);
break; // TODO: might not be correct. Was : Exit Select

break;
case 4:
//4桁(MMDD)の场合
inYear = year;
inMonth = dateStr.Substring(0, 2);
inDay = dateStr.Substring(2, 2);
break; // TODO: might not be correct. Was : Exit Select

break;
case 3:
//3桁(MDD)の场合
inYear = year;
inMonth = "0" + dateStr.Substring(0, 1);
inDay = dateStr.Substring(1, 2);
break; // TODO: might not be correct. Was : Exit Select

break;
case 2:
//2桁(DD)の场合
inYear = year;
inMonth = month;
inDay = dateStr.Substring(0, 2);
break; // TODO: might not be correct. Was : Exit Select

break;
case 1:
//1桁(D)の场合
inYear = year;
inMonth = month;
inDay = "0" + dateStr.Substring(0, 1);
break; // TODO: might not be correct. Was : Exit Select

break;
default:
//それ以外の桁がきた场合はエラー
return false;
}
//日付チェック
if (Information.IsDate(convertSlash(inYear + inMonth + inDay))) {
str = inYear + inMonth + inDay;
}
else {
return false;
}

return true;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
贾森chen
2010-02-10 · 超过37用户采纳过TA的回答
知道答主
回答量:311
采纳率:0%
帮助的人:0
展开全部
''' <summary>
''' 日付作成
''' </summary>
''' <param name="str"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Boolean CreateDate(String str)
{
If (String.IsNullOrEmpty(str))
{
return false;
}

Int32 int_ As = 0;
If (!Int32.TryParse(str,int_))
{
return false;
}

String dateStr = str;
String inYear;
String inMonth;
String inDay;

'现在の日付を取得
String nowdate = DateTime.Now.toString("yyyyMMdd");
'年を取得
String year = nowdate.Substring(0, 4);
'月を取得
String month = nowdate.Substring(4, 2);

Switch (dateStr.Length)
{
Case 8:
'8桁(YYYYMMDD)の场合
inYear = dateStr.Substring(0, 4);
inMonth = dateStr.Substring(4, 2);
inDay = dateStr.Substring(6, 2);
break;
Case 6:
'6桁(YYMMDD)の场合
inYear = year.Substring(0, 2) + dateStr.Substring(0, 2);
inMonth = dateStr.Substring(2, 2);
inDay = dateStr.Substring(4, 2);
break;
Case 4:
'4桁(MMDD)の场合
inYear = year;
inMonth = dateStr.Substring(0, 2);
inDay = dateStr.Substring(2, 2);
break;
Case 3:
'3桁(MDD)の场合
inYear = year;
inMonth = "0" + dateStr.Substring(0, 1);
inDay = dateStr.Substring(1, 2);
break;
Case 2:
'2桁(DD)の场合
inYear = year;
inMonth = month;
inDay = dateStr.Substring(0, 2);
break;
Case 1:
'1桁(D)の场合
inYear = year;
inMonth = month;
inDay = "0" + dateStr.Substring(0, 1);
break;
default:
'それ以外の桁がきた场合はエラー
return false;
}
'日付チェック
if (IsDate(convertSlash(inYear + inMonth + inDay)))
{
str = inYear + inMonth + inDay;
else
return false;
}

return true;
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式