解决使用 js 和 C# 提取日期的问题
我正在使用 2 个程序,并且必须使用解决方法,因为它们不兼容。在一个平台中,我使用日期选择器,当您选择日期时,它会将所选日期拉入像这样的字符串格式。 2011 年 9 月 8 日上午 12:00:00。我需要使用 javascript/c# 将日期本身解析为一个新字符串来显示 (09/08/2011) mm/dd/yyyy 但我画了一个空白。
我已经想出了一些与这些路线相符的东西,但它似乎不起作用,我最终还是抓住了救命稻草。
function OnDateSelected(sender, e) {
var str = document.getElementById("REQ_ER_DATE_PICK_PLACEHOLDER").Text = REQ_ER_DATE_PICK.SelectedDate.ToString();
var trimmed = str.Split(' ')[0].Trim();
var x = DateTime.Parse(trimmed);
document.getElementById("REQ_ER_DATE_PICK_PLACEHOLDER").Text = str;
}
任何帮助将非常感激。
I'm working with 2 programs and have to use a work around because they aren't compatible. In one platform I'm using a date picker, which when you pick a date pulls date selected into a string format like this. 9/8/2011 12:00:00 AM. I need to be parse out the date by itself into a new string to display (09/08/2011) mm/dd/yyyy using javascript/c# but am drawing a blank.
I've come up with something aling these lines, but it doesn't seem to work and I'm grasping at straws at the end of the day.
function OnDateSelected(sender, e) {
var str = document.getElementById("REQ_ER_DATE_PICK_PLACEHOLDER").Text = REQ_ER_DATE_PICK.SelectedDate.ToString();
var trimmed = str.Split(' ')[0].Trim();
var x = DateTime.Parse(trimmed);
document.getElementById("REQ_ER_DATE_PICK_PLACEHOLDER").Text = str;
}
Any help would be very much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您被允许使用外部库来解决您的问题,您应该查看 http://www.datejs.com/< /a>
它允许您将各种字符串格式解析为 javascript 日期对象。我真的很喜欢这个图书馆,每当我需要处理日期之类的事情时都会使用它。
对于你的问题,你只需使用这个:
If you're allowed to use external libraries to solve your problem you should look into http://www.datejs.com/
It allows you to parse various string formats into javascript date objects. I really love the library and use it whenever I need to mess with dates and what not.
For your problem specifically you would just use this: