gpt4 book ai didi

c# - 复选框内容中日期的字符串格式

转载 作者:行者123 更新时间:2023-11-30 20:33:42 24 4
gpt4 key购买 nike

我有一个我想说的CheckBox

"Load Prior to: 01/01/2001"

但是内容却说;

"Load Prior to: 01 01 2001"

基本上没有斜杠。这是我设置内容的方式;

oldContactsCheckBox.Content = 
"Load Contracts Prior To: " +
DateTime.Today.AddYears(-3).ToString("dd/MM/yyyy");

我怎样才能更改它以便在格式中包含斜线?

最佳答案

尝试转义:

https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx#escape

oldContactsCheckBox.Content = 
"Load Contracts Prior To: " +
DateTime.Today.AddYears(-3).ToString(@"dd\/MM\/yyyy");

更好的实现是字符串插值 (C# 6.0):

oldContactsCheckBox.Content = 
$@"Load Contracts Prior To: {DateTime.Today.AddYears(-3):dd\/MM\/yyyy}";

格式化:

oldContactsCheckBox.Content = string.Format(
@"Load Contracts Prior To: {0:dd\/MM\/yyyy}",
DateTime.Today.AddYears(-3));

关于c# - 复选框内容中日期的字符串格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39960136/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com