更改日期变量格式 [英] Change Date Variable Formats
本文介绍了更改日期变量格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用自定义日期变量格式而不更改区域设置。
ex:
Dim mydate as date
mydate =30/05/2014
它显示以下错误
从字符串转换2014年5月30日到类型'日期'无效。
当我的短日期格式是MM / yyyy / dd。
如何在区域设置中更改错误而不更改短日期格式。
解决方案
MyDate = CDate (20/05/2014)。ToShortDateString
或
MyDate = Convert.ToDateTime(20 / 05/2014)。ToShortDateString
试试这个: -
Dim mydate as date
mydate = DateTime.ParseExact( 30/05/2014,< span class =code-string> MM / yyyy / dd,CultureInfo.InvariantCulture);
SimpleDateFormat sdf = new SimpleDateFormat(MM:yyyy:dd);
日期日期=新日期();
String time = sdf.format(date);
System.out.println(时间);
Hi,
I want to use custom date variable formats without changing the regional settings.
ex:
Dim mydate as date
mydate = "30/05/2014"
It shows the following error
"Conversion from string "30/05/2014" to type 'Date' is not valid."
when my short date format is MM/yyyy/dd.
How to rectify the error without changing short date format in Regional Settings.
解决方案
MyDate = CDate("20/05/2014").ToShortDateString
OR
MyDate = Convert.ToDateTime("20/05/2014").ToShortDateString
try this:-
Dim mydate as date mydate= DateTime.ParseExact("30/05/2014", "MM/yyyy/dd",CultureInfo.InvariantCulture);
SimpleDateFormat sdf = new SimpleDateFormat("MM:yyyy:dd"); Date date = new Date(); String time = sdf.format(date); System.out.println(time);
这篇关于更改日期变量格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文