

更新一些常用的golang函数(笔记)
source link: https://surest.cn/archives/180/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

更新一些常用的golang函数(笔记)
带路径的情况下获取文件名称
filepath.Base(filename)
获取文件后缀名
filepath.Ext(filename)
获取文件mime(contentType)类型
mimeType := mime.TypeByExtension(filepath.Ext(filename))
获取当前时间或者增加当前时间(格式化后)
time.Now().Add(duration).Format("2006-01-02 15:04:05")
时间相关处理
format := "2006-01-02 15:04:05"
now := time.Now()
//now, _ := time.Parse(format, time.Now().Format(format))
a, _ := time.Parse(format, "2015-03-10 11:00:00")
b, _ := time.Parse(format, "2015-03-10 16:00:00")
fmt.Println(now.Format(format), a.Format(format), b.Format(format))
fmt.Println(now.After(a))
fmt.Println(now.Before(a))
fmt.Println(now.After(b))
fmt.Println(now.Before(b))
fmt.Println(a.After(b))
fmt.Println(a.Before(b))
fmt.Println(now.Format(format), a.Format(format), b.Format(format))
fmt.Println(now.Unix(), a.Unix(), b.Unix())
func Now() time.Time {
now := time.Now()
local, _ := time.LoadLocation("local")
//local, _ := time.LoadLocation("Asia/Shanghai")
now = now.In(local)
return now
}
查找字符串 索引位置
k := "1.jpg"
strings.IndexByte(k, '.jpg')
本文由 邓尘锋 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: May 16, 2021 at 03:17 pm
Recommend
-
33
本文为转载,原文: Golang中的一些常用的简单算法 Gola...
-
47
参考 golang 函数以及函数和方法的区别 在接触到go之前,我认为函数和方法只是同一个东西的两个名字而已(在我熟悉的c/c++,python,java中没有明...
-
8
laravel备忘录(更新中)这里主要记录一些能够提高效率的一点东西,因为有些东西的确是用的频率比较少,难记住,但有时候又非常必要的添加sql输出DB::connection('mysql_learn_record')->listen(fu...
-
8
Tensorflow一些常用基本概念与函数(4) ...
-
7
go-to-php 用Golang封装PHP常用的函数,为了区分PHP与Go中的函数,go-to-php封装的函数,都是在对应的PHP函数的前面加上大写的 P 。 Pallord 函数除外。相关代码点击
-
12
一些不常用的PHP字符类型检测函数 - 何晓东的博客 | alpha blog主要是 Ctype 扩展所提供的函数,用来检测在当前的区域设定下,一个字符或者字符串,是否仅包含指定类型的字符。此类函数用来替代简单的正则验证,效率高于正则验证。参数为字符串,如果给...
-
3
【笔记】Excl中的常用函数 发表于 2022-05-05 Waline:...
-
8
python与matlab一些常用函数互转 原创 ldc_1257309054 2022-06-09 16...
-
1
Docker常用命令笔记(持续补充更新) 发布:3小时前 更新:3小时前...
-
10
package example import ( "archive/zip" "bufio" "compress/gzip" "crypto/md5" "crypto/sha1" "crypto/sha256" "crypto/sha512" "fmt" "io" "log" "net/http" "os" "path/filepath" "strings" "time" )
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK