Code Monkey home page Code Monkey logo

strftime's Introduction

strftime for Go

Test License: MIT go.dev reference

Q: Why? We already have time.Format.

A: Yes, but it becomes tricky to use if if you have string with things other than time in them. (like /path/to/%Y/%m/%d/report)

Installing

go get github.com/tebeka/strftime

Example

str, err := strftime.Format("%Y/%m/%d", time.Now())

Contact

https://github.com/tebeka/strftime

strftime's People

Contributors

tebeka avatar

Stargazers

ik5 avatar gangge avatar Öner Çiller avatar Uğur Özyılmazel avatar Michael Corrado avatar GAURAV avatar WeizhongTu avatar Mikkel H Madsen avatar Damon Zhao avatar

Watchers

 avatar Andrew Sellers avatar James Cloos avatar  avatar

Forkers

vforks arnodel

strftime's Issues

%I should pad zero

Description

As title, %I should pad zero for 1-9.

Sample code

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/tebeka/strftime"
)

func main() {
	t := time.Date(2020, 07, 27, 9, 8, 7, 0, time.UTC)
	str, err := strftime.Format("%I:%M:%S %p", t)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(str) // 9:08:07 AM but should be 09:08:07 AM
}

For reference,

 % python -c "from datetime import datetime; print(datetime.strftime(datetime.now(), '%I'))"
06
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int main(void)
{
  struct tm tm;
  char buf[255];

  memset(&tm, 0, sizeof(struct tm));
  strptime("09:08:07", "%T", &tm);
  strftime(buf, sizeof(buf), "%I:%M:%S %p", &tm);
  puts(buf); // 09:08:07 AM
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.