diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
index 7d97fed..2f8170d 100644
--- a/libgfortran/configure.ac
+++ b/libgfortran/configure.ac
@@ -267,7 +267,7 @@ alarm access fork execl wait setmode execve pipe dup2 close \
 strcasestr getrlimit gettimeofday stat fstat lstat getpwuid vsnprintf dup \
 getcwd localtime_r gmtime_r getpwuid_r ttyname_r clock_gettime \
 readlink getgid getpid getppid getuid geteuid umask getegid \
-secure_getenv __secure_getenv)
+secure_getenv __secure_getenv GetTickCount64)
 
 # Check strerror_r, cannot be above as versions with two and three arguments exist
 LIBGFOR_CHECK_STRERROR_R
diff --git a/libgfortran/intrinsics/system_clock.c b/libgfortran/intrinsics/system_clock.c
index 87a87e2..e4590e6 100644
--- a/libgfortran/intrinsics/system_clock.c
+++ b/libgfortran/intrinsics/system_clock.c
@@ -29,6 +29,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include "time_1.h"
 
 
+#if !defined(_WIN32)
+
 /* POSIX states that CLOCK_REALTIME must be present if clock_gettime
    is available, others are optional.  */
 #if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_CLOCK_GETTIME_LIBRT)
@@ -105,6 +107,8 @@ gf_gettime_mono (time_t * secs, long * nanosecs, long * tck)
 #endif
 }
 
+#endif /* _WIN32  */
+
 extern void system_clock_4 (GFC_INTEGER_4 *, GFC_INTEGER_4 *, GFC_INTEGER_4 *);
 export_proto(system_clock_4);
 
@@ -121,6 +125,19 @@ void
 system_clock_4(GFC_INTEGER_4 *count, GFC_INTEGER_4 *count_rate,
 	       GFC_INTEGER_4 *count_max)
 {
+#ifdef _WIN32
+  if (count)
+    {
+      uint32_t cnt = GetTickCount ();
+      if (cnt > GFC_INTEGER_4_HUGE)
+	cnt -= GFC_INTEGER_4_HUGE - 1;
+      *count = cnt;
+    }
+  if (count_rate)
+    *count_rate = 1000;
+  if (count_max)
+    *count_max = GFC_INTEGER_4_HUGE;
+#else
   GFC_INTEGER_4 cnt;
   GFC_INTEGER_4 mx;
 
@@ -158,6 +175,7 @@ system_clock_4(GFC_INTEGER_4 *count, GFC_INTEGER_4 *count_rate,
     *count_rate = tck;
   if (count_max != NULL)
     *count_max = mx;
+#endif
 }
 
 
@@ -167,6 +185,26 @@ void
 system_clock_8 (GFC_INTEGER_8 *count, GFC_INTEGER_8 *count_rate,
 		GFC_INTEGER_8 *count_max)
 {
+#ifdef _WIN32
+#ifdef HAVE_GETTICKCOUNT64
+  if (count)
+    {
+      uint64_t cnt = GetTickCount64 ();
+      if (cnt > GFC_INTEGER_8_HUGE)
+	cnt -= GFC_INTEGER_8_HUGE - 1;
+      *count = cnt;
+    }
+  if (count_max)
+    *count_max = GFC_INTEGER_8_HUGE;
+#else
+  if (count)
+    *count = GetTickCount ();
+  if (count_max)
+    *count_max = (uint32_t) -1;
+#endif
+  if (count_rate)
+    *count_rate = 1000;
+#else
   GFC_INTEGER_8 cnt;
   GFC_INTEGER_8 mx;
 
@@ -204,4 +242,5 @@ system_clock_8 (GFC_INTEGER_8 *count, GFC_INTEGER_8 *count_rate,
     *count_rate = tck;
   if (count_max != NULL)
     *count_max = mx;
+#endif
 }
diff --git a/libgfortran/intrinsics/time_1.h b/libgfortran/intrinsics/time_1.h
index f21e0ea..b363dfe 100644
--- a/libgfortran/intrinsics/time_1.h
+++ b/libgfortran/intrinsics/time_1.h
@@ -101,7 +101,7 @@ localtime_r (const time_t * timep, struct tm * result)
    CPU_TIME intrinsics.  Returns 0 for success or -1 if no
    CPU time could be computed.  */
 
-#ifdef __MINGW32__
+#ifdef _WIN32
 
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
