任何人都知道C#中Java的SimpleDateFormat等价类?我想知道我是否可以使用C#中的自定义日期和时间格式字符串转换以下java代码
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
TimeZone tz = TimeZone.getDefault();
format.setTimeZone(TimeZone.getTimeZone("GMT"));
str = format.format(new Date());
Run Code Online (Sandbox Code Playgroud)
Joh*_*mer 11
您可以使用DateTime的ToString()方法,并指定自定义格式,你想要的DateTime是在输出在这种情况下:
// US culture
var usCulture = new CultureInfo("en-US");
// Get current UTC time.
var utcDate = DateTime.UtcNow;
// Change time to match GMT + 1.
var gmt1Date = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(utcDate, "W. Europe Standard Time");
// Output the GMT+1 time in our specified format using the US-culture.
var str = gmt1Date.ToString("ddd, dd MMM yyyy HH:mm:ss z", usCulture);
Run Code Online (Sandbox Code Playgroud)
请注意,.NET相当于EEE是ddd.