登录
首页 » C# » PHP中的 dateline 转换成 c#中的 datetime 方法 UNIX时间转换

PHP中的 dateline 转换成 c#中的 datetime 方法 UNIX时间转换

于 2013-11-14 发布
0 220
下载积分: 1 下载次数: 0

代码说明:

在众多的PHP MySQL的应用之中,存储在MySQL中的时间都是一串数字,后经查这个格式的日期叫做:Unix Timestamp;Unix的timestamp是一组数字,表示从1970年1月1日以来的秒数。今天在进行C#应用开发时需要对MySQL中的数据进行操作,写出以下方法供大家参考。主要应用到的类库有:System.TimeZone应用的方法:返回对应于指定协调通用时间 (UTC) 的本地时间。public virtual DateTime ToLocalTime(   DateTime time);1、将系统时间转换成UNIX时间戳            DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1));            DateTime dtNow = DateTime.Parse(DateTime.Now.ToString());            TimeSpan toNow = dtNow.Subtract(dtStart);            string timeStamp = toNow.Ticks.ToString();            timeStamp = timeStamp.Substring(0,timeStamp.Length - 7);    2、将UNIX时间戳转换成系统时            string timeStamp = "1176686120";            DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1));            long lTime = long.Parse(timeStamp "0000000");            TimeSpan toNow = new TimeSpan(lTime);            DateTime dtResult = dtStart.Add(toNow);

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • C#多线程学习
    C#多线程例子
    2013-10-31下载
    积分:1
  • C#(WinForm)HTML编辑器 实例源码
    C#(WinForm)HTML编辑器 实例源码
    2013-12-28下载
    积分:1
  • 于MadgwickAHRS算法的3D呈像实现
    基于MadgwickAHRS的九轴数据转换为四元数算法的3D呈像图
    2020-12-11下载
    积分:1
  • C# 套打Demo
    套打Demo 【核心代码】using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Drawing.Printing;namespace Print_Demo{ public partial class Form1 : Form { public PrintDocument printDt = new PrintDocument(); //打印文档对象 Font printFont; //打印使用的字体 public Form1() { InitializeComponent(); } void printDt_PrintPage(object sender, PrintPageEventArgs e) { float pointX = 10; float pointY = 10; e.Graphics.DrawString("打印内容", new Font("宋体", 16F), Brushes.Black, pointX 60, pointY); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 26,pointX 300,pointY 26); e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY 35); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 56, pointX 300, pointY 56); e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY 65); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 86, pointX 300, pointY 86); e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY 95); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 116, pointX 300, pointY 116); e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY 125); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 146, pointX 300, pointY 146); e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY 155); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 176, pointX 300, pointY 176); e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY 185); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 206, pointX 300, pointY 206); e.Graphics.DrawString("检测结果", printFont, Brushes.Black, pointX, pointY 233); e.Graphics.DrawString("通过", new Font("宋体",22F,FontStyle.Bold), Brushes.Black, pointX 90, pointY 225); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 265, pointX 300, pointY 265); e.Graphics.DrawString("单位名称", printFont, Brushes.Black, pointX, pointY 275); } private void Form1_Load(object sender, EventArgs e) { printDt.PrintPage = new PrintPageEventHandler(printDt_PrintPage); printFont = new Font("宋体", 12F); } private void btnPrint_Click(object sender, EventArgs e) { //PrintDialog printDlg = new PrintDialog(); //printDlg.Document = printDt; //printDlg.AllowPrintToFile = true; //printDlg.AllowCurrentPage = true; //printDlg.AllowSelection = true; //printDlg.ShowDialog(); //printDlg.ShowDialog(); printDt.Print(); } private void btnLook_Click(object sender, EventArgs e) { PrintPreviewDialog printPreview = new PrintPreviewDialog(); printPreview.PrintPreviewControl.Document = printDt; printPreview.ShowDialog(this); } }}
    2021-05-06下载
    积分:1
  • c# winform 打开窗体动态效果 实例源码
    c# winform 打开窗体动态效果 实例源码
    2014-06-13下载
    积分:1
  • C#串口调试工具源码下载
    C#串口调试工具源码下载
    2015-05-07下载
    积分:1
  • 金蝶云星空二次开发零入门(上)
    内容简介: 集成开发平台简介 开发环境部署准备 BOS业务常用操作业务服务讲解 单据插件开发基础
    2021-11-06 00:37:11下载
    积分:1
  • 模仿QQ播放器的简单音乐播放器
    可以从网易云音乐读取音乐,添加本地音乐等
    2016-05-11下载
    积分:1
  • c#任务管理器 示例代码
    自己做的c#任务管理器
    2014-09-19下载
    积分:1
  • C#与SAP系统接口
    NCO3.0的应用说明
    2015-03-26下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载