asp.net获取系统当前时间的方法:
DateTime.Now.ToString(); // 2008-9-4 20:02:10
DateTime.Now.ToLocalTime().ToString(); // 2008-9-4 20:12:12
写在js中:
1)
//时间戳 日志用
var tm1 = new Date().getTime();
function getData(n) {
n = new Date(n)
return n.toLocaleDateString().replace(/\//g, "-") + " " + n.toTimeString().substr(0, 8)
}
tm2 = getData(tm1) //'2022-1-18 10:09:06'
alert(tm2);
2)
<script type="text/javascript">
function getNowTime() {
var date = new Date();
this.year = date.getFullYear();
this.month = date.getMonth() + 1;
this.date = date.getDate();
this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
this.milliSeconds = date.getMilliseconds();
var currentTime = this.year+'-'+this.month + '-' + this.date + ' ' + this.hour + ':' + this.minute + ':' + this.second + '.' + this.milliSeconds;
return currentTime;
}
</script>
写在 *.aspx.cs中
protected void Page_Load(object sender, EventArgs e)
{
//日志记入
String strTest = "被修改";
String ts1 = DateTime.Now.ToString();
System.IO.File.WriteAllText(@"D:\VS2015\SSC3\log.txt", '\n' + ts1 + "_" + strTest);
}
写在 *.ashx中
string mytime = DateTime.Now.ToString(); //时间戳_年月日时分秒
string milliSeconds =context.Request["myTime"].ToString();// 时间戳_毫秒
在*.aspx中要加入以下代码
var tm1 = getTimestamp();
$.ajax({
url: "Handler3.ashx", //变更内容_写入日志
datatype: "json",
data: { "RequestType": "log_data2", "DBID": DBID, "beforeValue": beforeValue, "fieldName": fieldName, "myTime": tm1 },
success: function (data) {
//注释:返回结果,此处不需要了
},
error: function (error) {
alert(error.responseText);
}
});
写在Form中
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.toolStripStatusLabel2.Text = DateTime.Now.ToShortDateString(); //获取系统时间
}
private void button1_Click(object sender, EventArgs e)
{
this.toolStripProgressBar1.Minimum = 0;
this.toolStripProgressBar1.Maximum = 5000;
this.toolStripProgressBar1.Step = 2;
for (int i = 0; i <= 4999; i++)
{
this.toolStripProgressBar1.PerformStep(); // 工具栏底部滚动进度条
}
}
}