社区
C#
帖子详情
怎么样判断一个数据是不是DateTime 类型的
MScharlie
2005-02-02 03:41:14
谢谢
...全文
602
10
打赏
收藏
怎么样判断一个数据是不是DateTime 类型的
谢谢
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
10 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
manonroad
2005-02-02
打赏
举报
回复
1
我总结一下。如果你仅仅需要判断这个数据是否为DateTime, 可以用is.但是如果他是一个string,你需要用到Parse。
meixiaofeng
2005-02-02
打赏
举报
回复
1
楼上说的好,回答问题就地简单明了
gsky
2005-02-02
打赏
举报
回复
1
假设要判断的字符串为 s
if ( s is DateTime)
{
.....
}
harisonh2l
2005-02-02
打赏
举报
回复
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace DateTimePra
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(104, 176);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(80, 80);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
DateTime dt = Convert.ToDateTime(this.textBox1.Text);
MessageBox.Show(dt.ToString());
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
liduke
2005-02-02
打赏
举报
回复
用is
if (obj is DateTime)
{
(obj as DattTime).xxxxx
}
北京的雾霾天
2005-02-02
打赏
举报
回复
用是用is运算符:
is 运算符用于检查对象的运行时类型是否与给定类型兼容。
manonroad
2005-02-02
打赏
举报
回复
try
{
DataTime edate = DateTime.Parse(yourData);
}
catch
{
}
北京的雾霾天
2005-02-02
打赏
举报
回复
这样来做:
object tmpObj = new DateTime(2005,2,2);
if ( tmpObj is DateTime)
{
Console.WriteLine("tmpObj 是DateTime类型的数据");
}
Edelweissobject
2005-02-02
打赏
举报
回复
try{
Convert.ToDateTime();}
}
catch{
}
LoveCherry
2005-02-02
打赏
举报
回复
try{Convert.ToDateTime();}
python
判断
是否是
datetime
.
datetime
类型
我有
一个
变量,我需要知道它是否是
一个
datetime
对象. 到目前为止,我一直在使用以下hack函数来检测
datetime
对象: if ‘
datetime
.
datetime
’ in str(type(variable)): print ‘yes’ 但是真的应该有一种方法来检测什么...
(十二)
datetime
数据
类型
目录一:python的
datetime
类型
:二:pandas中的
数据
转换成
datetime
:三:提取日期的各个部分:四:日期运算和Timedalta:5: 处理股票
数据
:6:日期范围: 一:python的
datetime
类型
: 二:pandas中的
数据
转换成...
从 varchar
数据
类型
到
datetime
数据
类型
的转换产生
一个
超出范围的值报错
从 varchar
数据
类型
到
datetime
数据
类型
的转换产生
一个
超出范围的值 这个varchar格式是没错的,是因为
datetime
这个
数据
类型
有时间数值的范围限定,当超出时间范围时就抛出这个错误。 如果
类型
是“
datetime
” ...
mysql
datetime
数据
类型
_
datetime
数据
类型
MySQL日期
数据
类型
datetime
.
datetime
类型
:可用于需要同时包含日期和时间信息的值。(推荐学习:MySQL视频教程)
datetime
:MySQL 以 'YYYY-MM-DD HH:mm:ss'格式检索与显示
DATETIME
类型
。
类型
大小(字节)范围格式用途...
SQL Server 从 varchar
数据
类型
到
datetime
数据
类型
的转换产生
一个
超出范围的值。
在使用SQL Server 时遇到,从 varchar
数据
类型
到
datetime
数据
类型
的转换产生
一个
超出范围的值。错误 一般是varchar
类型
的
数据
格式不正确. 解决步骤:
判断
找出
数据
中报错的
数据
查看是否含有格式不正确的
数据
,例如...
C#
110,536
社区成员
642,578
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章