MCPcopy Index your code
hub / github.com/dromara/carbon

github.com/dromara/carbon @v2.6.16

repository ↗ · DeepWiki ↗ · release v2.6.16 ↗ · Ask this repo → · + Follow
2,095 symbols 10,946 edges 107 files 544 documented · 26% updated 2d agov2.6.16 · 2026-01-28★ 5,2202 open issues
README

carbon

Carbon Release Go Test Go Report Card Go Coverage Carbon Doc Awesome HelloGitHub License

日本語 | English | 简体中文 | 한국어

イントロ

Carbon は軽量でセマンティックで開発者に優しい golang 時間処理ライブラリで、サードパーティ製ライブラリに依存せず、ユニットテストのカバー率は 100% で、docker に公式採用され、awesome-gohello-github にも収録されています。

docker

リポジトリ

github.com/dromara/carbon

gitee.com/dromara/carbon

gitcode.com/dromara/carbon

クイックスタート

インストール

go version >= 1.18

// github から使う
go get -u github.com/dromara/carbon/v2
import "github.com/dromara/carbon/v2"

// gitee から使う
go get -u gitee.com/dromara/carbon/v2
import "gitee.com/dromara/carbon/v2"

// gitcode から使う
go get -u gitcode.com/dromara/carbon/v2
import "gitcode.com/dromara/gitcode/v2"

Carbondromara 組織に寄付されたためリポジトリのURLが変更されました。以前のリポジトリ golang-module/carbon を使用している場合はgo.modで新しいリポジトリURLに変更するか下記コマンドを実行します

go mod edit -replace github.com/golang-module/carbon/v2 = github.com/dromara/carbon/v2

使い方と例

デフォルトのタイムゾーンはUTC、ロケールは英語、週の開始日は月曜日、週末は土曜日日曜日

carbon.SetTestNow(carbon.Parse("2020-08-05 13:14:15.999999999"))
carbon.IsTestNow() // true

carbon.Now().ToString() // 2020-08-05 13:14:15.999999999 +0000 UTC
carbon.Yesterday().ToString() // 2020-08-04 13:14:15.999999999 +0000 UTC
carbon.Tomorrow().ToString() // 2020-08-06 13:14:15.999999999 +0000 UTC

carbon.Parse("2020-08-05 13:14:15").ToString() // 2020-08-05 13:14:15 +0000 UTC
carbon.Parse("2022-03-08T03:01:14-07:00").ToString() // 2022-03-08 10:01:14 +0000 UTC

carbon.ParseByLayout("It is 2020-08-05 13:14:15", "It is 2006-01-02 15:04:05").ToString() // 2020-08-05 13:14:15 +0000 UTC
carbon.ParseByFormat("It is 2020-08-05 13:14:15", "\\I\\t \\i\\s Y-m-d H:i:s").ToString() // 2020-08-05 13:14:15 +0000 UTC

carbon.CreateFromDate(2020, 8, 5).ToString() // 2020-08-05 00:00:00 +0000 UTC
carbon.CreateFromTime(13, 14, 15).ToString() // 2020-08-05 13:14:15 +0000 UTC
carbon.CreateFromDateTime(2020, 8, 5, 13, 14, 15).ToString() // 2020-08-05 13:14:15 +0000 UTC
carbon.CreateFromTimestamp(1596633255).ToString() // 2020-08-05 13:14:15 +0000 UTC

carbon.Parse("2020-07-05 13:14:15").DiffForHumans() // 1 month before
carbon.Parse("2020-07-05 13:14:15").SetLocale("zh-CN").DiffForHumans() // 1 月前

carbon.ClearTestNow()
carbon.IsTestNow() // false

より多くの使用例については、公式ドキュメントをご覧ください。

性能テストレポートについては、ベンチマークレポートをご参照ください

リファレンス

コントリビューター

Carbon に貢献してくれた以下のすべてに感謝します:

翻訳者

Carbon を他のローカライズ言語に翻訳してくださる方を募集しています

Carbon に新しいローカライズ言語サポートを追加する方法

スポンサー

Carbon は非営利のオープンソースプロジェクトです,Carbon をサポートしたい場合は、開発者のために コーヒーを1杯購入 できます

謝辞

Carbon は無料の JetBrains オープンソースライセンスを取得しました,これに感謝します

JetBrains

オープンソースプロトコル

CarbonMIT オープンソースプロトコルに準拠しており、詳細は LICENSE を参照してください

Extension points exported contracts — how you extend this code

LayoutTyper (Interface)
LayoutTyper defines a LayoutTyper interface [1 implementers]
type_interface.go
FormatTyper (Interface)
FormatTyper defines a FormatTyper interface. [1 implementers]
type_interface.go
TimestampTyper (Interface)
TimestampTyper defines a TimestampTyper interface.
type_interface.go

Core symbols most depended-on inside this repo

Parse
called by 2375
parser.go
ToString
called by 1277
outputer.go
Now
called by 1224
traveler.go
HasError
called by 655
comparer.go
NewCarbon
called by 428
carbon.go
ToDateString
called by 351
outputer.go
String
called by 347
type_carbon.go
IsInvalid
called by 306
comparer.go

Shape

Function 1,104
Method 901
Struct 59
TypeAlias 28
Interface 3

Languages

Go100%

Modules by API surface

traveler_unit_test.go80 symbols
traveler_example_test.go77 symbols
traveler_bench_test.go77 symbols
traveler.go77 symbols
outputer_unit_test.go67 symbols
outputer_example_test.go64 symbols
outputer.go64 symbols
outputer_bench_test.go63 symbols
comparer_unit_test.go61 symbols
comparer.go61 symbols
comparer_example_test.go59 symbols
comparer_bench_test.go59 symbols

Dependencies from manifests, versioned

filippo.io/edwards25519v1.1.0 · 1×
github.com/golang/snappyv1.0.0 · 1×
github.com/jackc/pgpassfilev1.0.0 · 1×
github.com/jackc/pgservicefilev0.0.0-2024060612052 · 1×
github.com/jackc/puddle/v2v2.2.2 · 1×
github.com/jinzhu/inflectionv1.0.0 · 1×

For agents

$ claude mcp add carbon \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact