求帮我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 展开
''' 日付作成
''' </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 展开
2个回答
展开全部
/// <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;
}
/// 日付作成
/// </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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
''' <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;
}
''' 日付作成
''' </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;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询