use new time API

R=bradfitz, gri, r, dsymonds
CC=golang-dev
https://golang.org/cl/5390042
diff --git a/src/pkg/net/dnsclient_unix.go b/src/pkg/net/dnsclient_unix.go
index bab5f2a..79a958e 100644
--- a/src/pkg/net/dnsclient_unix.go
+++ b/src/pkg/net/dnsclient_unix.go
@@ -29,7 +29,7 @@
 		return nil, &DNSError{Err: "name too long", Name: name}
 	}
 	out := new(dnsMsg)
-	out.id = uint16(rand.Int()) ^ uint16(time.Nanoseconds())
+	out.id = uint16(rand.Int()) ^ uint16(time.Now().UnixNano())
 	out.question = []dnsQuestion{
 		{name, qtype, dnsClassINET},
 	}
diff --git a/src/pkg/net/fd.go b/src/pkg/net/fd.go
index 70e04a2..5318c51 100644
--- a/src/pkg/net/fd.go
+++ b/src/pkg/net/fd.go
@@ -171,7 +171,7 @@
 }
 
 func (s *pollServer) Now() int64 {
-	return time.Nanoseconds()
+	return time.Now().UnixNano()
 }
 
 func (s *pollServer) CheckDeadlines() {
diff --git a/src/pkg/net/fd_windows.go b/src/pkg/net/fd_windows.go
index 7a16023..264b918 100644
--- a/src/pkg/net/fd_windows.go
+++ b/src/pkg/net/fd_windows.go
@@ -172,11 +172,12 @@
 		return 0, &OpError{oi.Name(), o.fd.net, o.fd.laddr, e}
 	}
 	// Wait for our request to complete.
+	// TODO(rsc): This should stop the timer.
 	var r ioResult
 	if deadline_delta > 0 {
 		select {
 		case r = <-o.resultc:
-		case <-time.After(deadline_delta):
+		case <-time.After(time.Duration(deadline_delta) * time.Nanosecond):
 			s.canchan <- oi
 			<-o.errnoc
 			r = <-o.resultc
diff --git a/src/pkg/net/hosts.go b/src/pkg/net/hosts.go
index ddfb074..e6674ba 100644
--- a/src/pkg/net/hosts.go
+++ b/src/pkg/net/hosts.go
@@ -11,7 +11,7 @@
 	"time"
 )
 
-const cacheMaxAge = int64(300) // 5 minutes.
+const cacheMaxAge = 5 * time.Minute
 
 // hostsPath points to the file with static IP/address entries.
 var hostsPath = "/etc/hosts"
@@ -21,14 +21,14 @@
 	sync.Mutex
 	byName map[string][]string
 	byAddr map[string][]string
-	time   int64
+	expire time.Time
 	path   string
 }
 
 func readHosts() {
-	now := time.Seconds()
+	now := time.Now()
 	hp := hostsPath
-	if len(hosts.byName) == 0 || hosts.time+cacheMaxAge <= now || hosts.path != hp {
+	if len(hosts.byName) == 0 || now.After(hosts.expire) || hosts.path != hp {
 		hs := make(map[string][]string)
 		is := make(map[string][]string)
 		var file *file
@@ -51,7 +51,7 @@
 			}
 		}
 		// Update the data cache.
-		hosts.time = time.Seconds()
+		hosts.expire = time.Now().Add(cacheMaxAge)
 		hosts.path = hp
 		hosts.byName = hs
 		hosts.byAddr = is
diff --git a/src/pkg/net/http/cgi/host_test.go b/src/pkg/net/http/cgi/host_test.go
index 4e97704..9a8d3c0 100644
--- a/src/pkg/net/http/cgi/host_test.go
+++ b/src/pkg/net/http/cgi/host_test.go
@@ -365,7 +365,7 @@
 
 	tries := 0
 	for tries < 15 && childRunning() {
-		time.Sleep(50e6 * int64(tries))
+		time.Sleep(50 * time.Millisecond * time.Duration(tries))
 		tries++
 	}
 	if childRunning() {
diff --git a/src/pkg/net/http/cookie.go b/src/pkg/net/http/cookie.go
index 6935014..cad8522 100644
--- a/src/pkg/net/http/cookie.go
+++ b/src/pkg/net/http/cookie.go
@@ -115,7 +115,7 @@
 						break
 					}
 				}
-				c.Expires = *exptime
+				c.Expires = exptime.UTC()
 				continue
 			case "path":
 				c.Path = val
@@ -146,8 +146,8 @@
 	if len(c.Domain) > 0 {
 		fmt.Fprintf(&b, "; Domain=%s", sanitizeValue(c.Domain))
 	}
-	if len(c.Expires.Zone) > 0 {
-		fmt.Fprintf(&b, "; Expires=%s", c.Expires.Format(time.RFC1123))
+	if c.Expires.Unix() > 0 {
+		fmt.Fprintf(&b, "; Expires=%s", c.Expires.UTC().Format(time.RFC1123))
 	}
 	if c.MaxAge > 0 {
 		fmt.Fprintf(&b, "; Max-Age=%d", c.MaxAge)
diff --git a/src/pkg/net/http/cookie_test.go b/src/pkg/net/http/cookie_test.go
index 24adf20..26bff93 100644
--- a/src/pkg/net/http/cookie_test.go
+++ b/src/pkg/net/http/cookie_test.go
@@ -123,7 +123,7 @@
 			Path:       "/",
 			Domain:     ".google.ch",
 			HttpOnly:   true,
-			Expires:    time.Time{Year: 2011, Month: 11, Day: 23, Hour: 1, Minute: 5, Second: 3, ZoneOffset: 0, Zone: "GMT"},
+			Expires:    time.Date(2011, 11, 23, 1, 5, 3, 0, time.UTC),
 			RawExpires: "Wed, 23-Nov-2011 01:05:03 GMT",
 			Raw:        "NID=99=YsDT5i3E-CXax-; expires=Wed, 23-Nov-2011 01:05:03 GMT; path=/; domain=.google.ch; HttpOnly",
 		}},
diff --git a/src/pkg/net/http/export_test.go b/src/pkg/net/http/export_test.go
index 3fe6586..13640ca 100644
--- a/src/pkg/net/http/export_test.go
+++ b/src/pkg/net/http/export_test.go
@@ -7,6 +7,8 @@
 
 package http
 
+import "time"
+
 func (t *Transport) IdleConnKeysForTesting() (keys []string) {
 	keys = make([]string, 0)
 	t.lk.Lock()
@@ -33,8 +35,8 @@
 	return len(conns)
 }
 
-func NewTestTimeoutHandler(handler Handler, ch <-chan int64) Handler {
-	f := func() <-chan int64 {
+func NewTestTimeoutHandler(handler Handler, ch <-chan time.Time) Handler {
+	f := func() <-chan time.Time {
 		return ch
 	}
 	return &timeoutHandler{handler, f, ""}
diff --git a/src/pkg/net/http/fcgi/child.go b/src/pkg/net/http/fcgi/child.go
index 529440c..c94b9a7 100644
--- a/src/pkg/net/http/fcgi/child.go
+++ b/src/pkg/net/http/fcgi/child.go
@@ -103,7 +103,7 @@
 	}
 
 	if r.header.Get("Date") == "" {
-		r.header.Set("Date", time.UTC().Format(http.TimeFormat))
+		r.header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
 	}
 
 	fmt.Fprintf(r.w, "Status: %d %s\r\n", code, http.StatusText(code))
diff --git a/src/pkg/net/http/fs.go b/src/pkg/net/http/fs.go
index 5aadac1..7f22188 100644
--- a/src/pkg/net/http/fs.go
+++ b/src/pkg/net/http/fs.go
@@ -148,11 +148,11 @@
 		}
 	}
 
-	if t, _ := time.Parse(TimeFormat, r.Header.Get("If-Modified-Since")); t != nil && d.Mtime_ns/1e9 <= t.Seconds() {
+	if t, err := time.Parse(TimeFormat, r.Header.Get("If-Modified-Since")); err == nil && !d.ModTime.After(t) {
 		w.WriteHeader(StatusNotModified)
 		return
 	}
-	w.Header().Set("Last-Modified", time.SecondsToUTC(d.Mtime_ns/1e9).Format(TimeFormat))
+	w.Header().Set("Last-Modified", d.ModTime.UTC().Format(TimeFormat))
 
 	// use contents of index.html for directory, if present
 	if d.IsDirectory() {
diff --git a/src/pkg/net/http/httptest/server.go b/src/pkg/net/http/httptest/server.go
index f09e826..5b02e14 100644
--- a/src/pkg/net/http/httptest/server.go
+++ b/src/pkg/net/http/httptest/server.go
@@ -7,14 +7,12 @@
 package httptest
 
 import (
-	"crypto/rand"
 	"crypto/tls"
 	"flag"
 	"fmt"
 	"net"
 	"net/http"
 	"os"
-	"time"
 )
 
 // A Server is an HTTP server listening on a system-chosen port on the
@@ -113,8 +111,6 @@
 	}
 
 	s.TLS = &tls.Config{
-		Rand:         rand.Reader,
-		Time:         time.Seconds,
 		NextProtos:   []string{"http/1.1"},
 		Certificates: []tls.Certificate{cert},
 	}
diff --git a/src/pkg/net/http/httputil/reverseproxy.go b/src/pkg/net/http/httputil/reverseproxy.go
index bfcb3ca..1dc83e7 100644
--- a/src/pkg/net/http/httputil/reverseproxy.go
+++ b/src/pkg/net/http/httputil/reverseproxy.go
@@ -31,11 +31,11 @@
 	// If nil, http.DefaultTransport is used.
 	Transport http.RoundTripper
 
-	// FlushInterval specifies the flush interval, in
-	// nanoseconds, to flush to the client while
-	// coping the response body.
+	// FlushInterval specifies the flush interval
+	// to flush to the client while copying the
+	// response body.
 	// If zero, no periodic flushing is done.
-	FlushInterval int64
+	FlushInterval time.Duration
 }
 
 func singleJoiningSlash(a, b string) string {
@@ -135,7 +135,7 @@
 
 type maxLatencyWriter struct {
 	dst     writeFlusher
-	latency int64 // nanos
+	latency time.Duration
 
 	lk   sync.Mutex // protects init of done, as well Write + Flush
 	done chan bool
diff --git a/src/pkg/net/http/pprof/pprof.go b/src/pkg/net/http/pprof/pprof.go
index c0327a9..2de14757 100644
--- a/src/pkg/net/http/pprof/pprof.go
+++ b/src/pkg/net/http/pprof/pprof.go
@@ -80,7 +80,7 @@
 		fmt.Fprintf(w, "Could not enable CPU profiling: %s\n", err)
 		return
 	}
-	time.Sleep(sec * 1e9)
+	time.Sleep(time.Duration(sec) * time.Second)
 	pprof.StopCPUProfile()
 }
 
diff --git a/src/pkg/net/http/serve_test.go b/src/pkg/net/http/serve_test.go
index 97a0b13..670b541 100644
--- a/src/pkg/net/http/serve_test.go
+++ b/src/pkg/net/http/serve_test.go
@@ -266,19 +266,19 @@
 	}
 
 	// Slow client that should timeout.
-	t1 := time.Nanoseconds()
+	t1 := time.Now()
 	conn, err := net.Dial("tcp", addr.String())
 	if err != nil {
 		t.Fatalf("Dial: %v", err)
 	}
 	buf := make([]byte, 1)
 	n, err := conn.Read(buf)
-	latency := time.Nanoseconds() - t1
+	latency := time.Now().Sub(t1)
 	if n != 0 || err != io.EOF {
 		t.Errorf("Read = %v, %v, wanted %v, %v", n, err, 0, io.EOF)
 	}
-	if latency < second*0.20 /* fudge from 0.25 above */ {
-		t.Errorf("got EOF after %d ns, want >= %d", latency, second*0.20)
+	if latency < 200*time.Millisecond /* fudge from 0.25 above */ {
+		t.Errorf("got EOF after %s, want >= %s", latency, 200*time.Millisecond)
 	}
 
 	// Hit the HTTP server successfully again, verifying that the
@@ -760,7 +760,7 @@
 		_, werr := w.Write([]byte("hi"))
 		writeErrors <- werr
 	})
-	timeout := make(chan int64, 1) // write to this to force timeouts
+	timeout := make(chan time.Time, 1) // write to this to force timeouts
 	ts := httptest.NewServer(NewTestTimeoutHandler(sayHi, timeout))
 	defer ts.Close()
 
@@ -782,7 +782,7 @@
 	}
 
 	// Times out:
-	timeout <- 1
+	timeout <- time.Time{}
 	res, err = Get(ts.URL)
 	if err != nil {
 		t.Error(err)
diff --git a/src/pkg/net/http/server.go b/src/pkg/net/http/server.go
index 0e8580a..125f3f2 100644
--- a/src/pkg/net/http/server.go
+++ b/src/pkg/net/http/server.go
@@ -347,7 +347,7 @@
 	}
 
 	if _, ok := w.header["Date"]; !ok {
-		w.Header().Set("Date", time.UTC().Format(TimeFormat))
+		w.Header().Set("Date", time.Now().UTC().Format(TimeFormat))
 	}
 
 	te := w.header.Get("Transfer-Encoding")
@@ -1084,7 +1084,6 @@
 	}
 	config := &tls.Config{
 		Rand:       rand.Reader,
-		Time:       time.Seconds,
 		NextProtos: []string{"http/1.1"},
 	}
 
@@ -1112,9 +1111,9 @@
 // (If msg is empty, a suitable default message will be sent.)
 // After such a timeout, writes by h to its ResponseWriter will return
 // ErrHandlerTimeout.
-func TimeoutHandler(h Handler, ns int64, msg string) Handler {
-	f := func() <-chan int64 {
-		return time.After(ns)
+func TimeoutHandler(h Handler, dt time.Duration, msg string) Handler {
+	f := func() <-chan time.Time {
+		return time.After(dt)
 	}
 	return &timeoutHandler{h, f, msg}
 }
@@ -1125,7 +1124,7 @@
 
 type timeoutHandler struct {
 	handler Handler
-	timeout func() <-chan int64 // returns channel producing a timeout
+	timeout func() <-chan time.Time // returns channel producing a timeout
 	body    string
 }
 
diff --git a/src/pkg/net/http/transport_test.go b/src/pkg/net/http/transport_test.go
index 7729797..6f50f6f 100644
--- a/src/pkg/net/http/transport_test.go
+++ b/src/pkg/net/http/transport_test.go
@@ -263,7 +263,7 @@
 				t.Fatalf(format, arg...)
 			}
 			t.Logf("retrying shortly after expected error: "+format, arg...)
-			time.Sleep(1e9 / int64(retries))
+			time.Sleep(time.Second / time.Duration(retries))
 		}
 		for retries >= 0 {
 			retries--
diff --git a/src/pkg/net/mail/message.go b/src/pkg/net/mail/message.go
index a1a86d3..e1afa32 100644
--- a/src/pkg/net/mail/message.go
+++ b/src/pkg/net/mail/message.go
@@ -89,14 +89,14 @@
 	}
 }
 
-func parseDate(date string) (*time.Time, error) {
+func parseDate(date string) (time.Time, error) {
 	for _, layout := range dateLayouts {
 		t, err := time.Parse(layout, date)
 		if err == nil {
 			return t, nil
 		}
 	}
-	return nil, errors.New("mail: header could not be parsed")
+	return time.Time{}, errors.New("mail: header could not be parsed")
 }
 
 // A Header represents the key-value pairs in a mail message header.
@@ -111,10 +111,10 @@
 var ErrHeaderNotPresent = errors.New("mail: header not in message")
 
 // Date parses the Date header field.
-func (h Header) Date() (*time.Time, error) {
+func (h Header) Date() (time.Time, error) {
 	hdr := h.Get("Date")
 	if hdr == "" {
-		return nil, ErrHeaderNotPresent
+		return time.Time{}, ErrHeaderNotPresent
 	}
 	return parseDate(hdr)
 }
diff --git a/src/pkg/net/mail/message_test.go b/src/pkg/net/mail/message_test.go
index 5653647..1f71cc4 100644
--- a/src/pkg/net/mail/message_test.go
+++ b/src/pkg/net/mail/message_test.go
@@ -82,34 +82,18 @@
 func TestDateParsing(t *testing.T) {
 	tests := []struct {
 		dateStr string
-		exp     *time.Time
+		exp     time.Time
 	}{
 		// RFC 5322, Appendix A.1.1
 		{
 			"Fri, 21 Nov 1997 09:55:06 -0600",
-			&time.Time{
-				Year:       1997,
-				Month:      11,
-				Day:        21,
-				Hour:       9,
-				Minute:     55,
-				Second:     6,
-				ZoneOffset: -6 * 60 * 60,
-			},
+			time.Date(1997, 11, 21, 9, 55, 6, 0, time.FixedZone("", -6*60*60)),
 		},
 		// RFC5322, Appendix A.6.2
 		// Obsolete date.
 		{
 			"21 Nov 97 09:55:06 GMT",
-			&time.Time{
-				Year:   1997,
-				Month:  11,
-				Day:    21,
-				Hour:   9,
-				Minute: 55,
-				Second: 6,
-				Zone:   "GMT",
-			},
+			time.Date(1997, 11, 21, 9, 55, 6, 0, time.FixedZone("GMT", 0)),
 		},
 	}
 	for _, test := range tests {
diff --git a/src/pkg/net/timeout_test.go b/src/pkg/net/timeout_test.go
index 3c884ca..f6e5238 100644
--- a/src/pkg/net/timeout_test.go
+++ b/src/pkg/net/timeout_test.go
@@ -17,7 +17,7 @@
 		return
 	}
 	defer fd.Close()
-	t0 := time.Nanoseconds()
+	t0 := time.Now()
 	fd.SetReadTimeout(1e8) // 100ms
 	var b [100]byte
 	var n int
@@ -27,7 +27,7 @@
 	} else {
 		n, err1 = fd.Read(b[0:])
 	}
-	t1 := time.Nanoseconds()
+	t1 := time.Now()
 	what := "Read"
 	if readFrom {
 		what = "ReadFrom"
@@ -35,8 +35,8 @@
 	if n != 0 || err1 == nil || !err1.(Error).Timeout() {
 		t.Errorf("fd.%s on %s %s did not return 0, timeout: %v, %v", what, network, addr, n, err1)
 	}
-	if t1-t0 < 0.5e8 || t1-t0 > 1.5e8 {
-		t.Errorf("fd.%s on %s %s took %f seconds, expected 0.1", what, network, addr, float64(t1-t0)/1e9)
+	if dt := t1.Sub(t0); dt < 50*time.Millisecond || dt > 150*time.Millisecond {
+		t.Errorf("fd.%s on %s %s took %s, expected 0.1s", what, network, addr, dt)
 	}
 }