func Format(format string, t time.Time) (result string, err error) {
	defer func() {
		if e := recover(); e != nil {
			result = ""
			err = e.(error)
		}
	}()
	fn := func(match string) string {
		return repl(match, t)
	}
	return fmtRe.ReplaceAllStringFunc(format, fn), nil
}
Format return string with % directives expanded.
Will return error on unknown directive.
package strftime
import (
	"fmt"
	"regexp"
	"time"
)
const (
	Version = "0.1.1"
	WEEK = time.Hour * 24 * 7
)
var conv = map[string]string{
	"%a": "Mon",          
	"%A": "Monday",       
	"%b": "Jan",          
	"%B": "January",      
	"%c": time.RFC1123,   
	"%d": "02",           
	"%H": "15",           
	"%I": "3",            
	"%m": "01",           
	"%M": "04",           
	"%p": "PM",           
	"%S": "05",           
	"%x": "01/02/2006",   
	"%X": "15:04:05 PM",  
	"%y": "06",           
	"%Y": "2006",         
	"%Z": "MST",          
}
var fmtRe *regexp.Regexp
func init() {
	fmtRe = regexp.MustCompile("%[%a-zA-Z]")
}
func repl(match string, t time.Time) string {
	if match == "%%" {
		return "%"
	}
	format, ok := conv[match]
	if ok {
		return t.Format(format)
	}
	switch match {
	case "%j":
		start := time.Date(t.Year(), time.January, 1, 0, 0, 0, 0, time.UTC)
		day := int(t.Sub(start).Hours()/24) + 1
		return fmt.Sprintf("%03d", day)
	case "%w":
		return fmt.Sprintf("%d", t.Weekday())
	case "%W", "%U":
		start := time.Date(t.Year(), time.January, 1, 23, 0, 0, 0, time.UTC)
		week := 0
		for start.Before(t) {
			week += 1
			start = start.Add(WEEK)
		}
		return fmt.Sprintf("%02d", week)
	}
	panic(fmt.Errorf("unknown directive - %s", match))
	return ""  
}