晚上失眠了一小会儿,然后突然想写个小程序.然后学习了下C#…嗯,打包一个小的时间转换工具,给自己用.嘿嘿,挺好玩的.
效果截图
** 下载地址:**
coding-文件分享
主要代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String unix = unixtimebox.Text;
if (unix == "" || unix.Length != 10)
{
MessageBox.Show(this, "unix时间格式错误!", "注意!", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
int unixtime = int.Parse(unix);
var time = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddSeconds(unixtime);
timebox.Text = time.ToString("yyyy-MM-dd HH:mm:ss");
}
private void button2_Click(object sender, EventArgs e)
{
String TimeStr = newTime.Text;
if (TimeStr == "" || TimeStr.Length != 19)
{
MessageBox.Show(this, "时间格式错误!", "注意!", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
var unix = DateTime.ParseExact(TimeStr, "yyyy-MM-dd HH:mm:ss", new System.Globalization.CultureInfo("zh-CN", true));
int x = (int)(unix - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))).TotalSeconds;
newUnix.Text = x.ToString();
}
}
}