如何在对象中格式化日期? [英] How do I format date in my object?

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

问题描述

在vb.net中我有一个对象

In vb.net I have an object

strEnteredDate

这是一个像这样的日期2018-03-29T10:26:20

我想将此日期格式化为2018-03-29。

我该怎么办?

我在下面尝试的是获得一个选项严格错误。



我尝试过:



strEnteredDate.ToString (yyyy-MM-ddThh:mm:ss)。替换(T,hh,:,mm,:,ss))

which is holding a date like this 2018-03-29T10:26:20
I would like to format this date to look like this 2018-03-29.
How do I do it?
What I have tried here below is getting an option strict error.

What I have tried:

strEnteredDate.ToString("yyyy-MM-ddThh: mm : ss").Replace("T", "hh", ":", "mm", ":", "ss"))

推荐答案

你有没有尝试

Did you try
strEnteredDate.ToString("yyyy-MM-dd")


我想你输入的'Object'strEnteredDate已经是一个字符串了。

所以你只需要从这个字符串中删除左边10个字符并将其写入一个新字符串(或相同)。

例如:
I suppose that your entered 'Object' strEnteredDate is allready a string.
So you only need to cut the left 10 chars from this string and write it into a new string (or the same).
For example like this :
strEnteredDate = strEnteredDate.substring(0,10)


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

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