我怎么才得到时间? [英] How do I get only the time?

查看:84
本文介绍了我怎么才得到时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码并显示日期和月份。我怎么才做到这一点?



我尝试过的事情:



i have this following code and its showing the date and month . how do i make it only the time ?

What I have tried:

Dim phOffz As TimeSpan = (TimeSpan.Parse("08:00"))
Dim myDt As DateTime = DateTime.Now.ToUniversalTime
Dim phtime As DateTime = myDt + phOffz

推荐答案

Google Gods为您提供了467,000个可能的答案: C#使用日期 [ ^ ]
The Google Gods have 467,000 possible answers for you: C# working with dates[^]


DateTime实例没有只有一个时间 - 它总是有日期组件。

如果要将实例的时间组件设置为当前日期,但指定的小时和分钟非常简单:

A DateTime instance does not have "only a time" - it always has a date component.
If you want to set the time component of an instance to the current date, but the hours and minutes specified that's pretty simple:
Dim phOffz As TimeSpan = (TimeSpan.Parse("08:00"))
Dim phTime As DateTime = DateTime.Now.[Date] + phOffz



如果你想要只显示时间,然后将其格式化为字符串:


If you want to display just the time, then format it to a string:

Dim phOffz As TimeSpan = (TimeSpan.Parse("08:00"))
Dim phTime As DateTime = DateTime.Now.[Date] + phOffz
Console.WriteLine(phTime.ToString("HH:mm"))


赞这个
phtime.ToString("HH:mm")


这篇关于我怎么才得到时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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