格式化当前日期 [英] Formatting the current date

查看:97
本文介绍了格式化当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要么我似乎找不到解决问题的正确方法,要么比我想象的要复杂得多,但是将当前日期分配给变量并将其格式化为特定格式的最简单方法是什么??基本上,我想做等效于 this VBA行的VB.net:

Either I just can't seem to find the right way to word the problem or it's a lot more complicated than I thought, but what is the easiest way to assign the current date to a variable and format it to a specific format? Basically, I want to do the VB.net equivalent of this VBA line:

formatted_date = Format(Date, "yyyy-m-d")

谢谢!

推荐答案

Dim formattedDate as String = DateTime.Now.ToString("yyyy-M-d")

请注意,大写M表示月份,小写m表示分钟.

Note that capital M is for month, lowercase m would get you minutes.

这篇关于格式化当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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