博文

目前显示的是 八月, 2019的博文

Thread & ConcurrentDictionary in C#

using System; using System.IO; using System.Text.RegularExpressions; using System.Threading.Tasks; public class Example {    public static async Task Main()    {       string pattern = @"\p{P}*\s+";       string[] titles = { "Sister Carrie", "The Financier" };       Task<int>[] tasks = new Task<int>[titles.Length];       for (int ctr = 0; ctr < titles.Length; ctr++) {          string s = titles[ctr];          tasks[ctr] = new Task<int>( () => {                                    // Number of words.                                    int nWords = 0;                           ...

Write log in ActionFilterAttribute in C#

ActionFilterAttribute public class JinFilter : System.Web.Http.Filters.ActionFilterAttribute {     public override Task OnActionExecutingAsync(HttpActionContext actionContext, CancellationToken cancellationToken)     {               WriteLog(actionContext);         return base.OnActionExecutingAsync(actionContext, cancellationToken);     }     private async void WriteLog(HttpActionContext actionContext)     {         try         {             System.Text.StringBuilder sb = new System.Text.StringBuilder();             sb.Append(actionContext.Request.Method.ToString() + " ");             sb.AppendLine(actionContext.Request.RequestUri.OriginalString);             sb.AppendLine(Convert.ToString(actionContext.Reque...

Unix timestamp Unix Time 1970

时间戳是自 1970 年 1 月 1 日(00:00:00 GMT)以来的秒数。它也被称为 Unix 时间戳(Unix Timestamp)。 获取现在的Unix时间戳(Unix timestamp)? Java time JavaScript Math.round(new Date().getTime()/1000) getTime()返回数值的单位是毫秒 Microsoft .NET / C# epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000 MySQL SELECT unix_timestamp(now()) Perl time PHP time() PostgreSQL SELECT extract(epoch FROM now()) Python 先 import time 然后 time.time() Ruby 获取Unix时间戳:Time.now 或 Time.new 显示Unix时间戳:Time.now.to_i SQL Server SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE()) Unix / Linux date +%s VBScript / ASP DateDiff("s", "01/01/1970 00:00:00", Now()) 其他操作系统 (如果Perl被安装在系统中) 命令行状态:perl -e "print time" 实现Unix时间戳(Unix timestamp) to 普通时间? Java String date = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new java.util.Date(Unix timestamp * 1000)) JavaScript 先 var unixTimestamp = new Date(Unix timestamp * 1000) 然后 commonTime = unixTimestamp.to...