--- a/src/lib.rs
+++ b/src/lib.rs
@@ -174,5 +174,5 @@
     use crate::{parse_duration, DateError, Dialect, Interval};
 
-    #[cfg(feature = "chrono")]
+    #[cfg(all(feature = "chrono", feature = "std"))]
     #[track_caller]
     fn format_chrono(d: &crate::types::DateTimeSpec, dialect: Dialect) -> String {
@@ -190,5 +190,5 @@
     }
 
-    #[cfg(feature = "time")]
+    #[cfg(all(feature = "time", feature = "std"))]
     #[track_caller]
     fn format_time(d: &crate::types::DateTimeSpec, dialect: Dialect) -> String {
@@ -222,5 +222,5 @@
                 Ok(date) => date,
             };
-            #[cfg(feature = "chrono")]
+            #[cfg(all(feature = "chrono", feature = "std"))]
             {
                 let output = format_chrono(&_date, dialect);
@@ -230,5 +230,5 @@
                 }
             }
-            #[cfg(feature = "time")]
+            #[cfg(all(feature = "time", feature = "std"))]
             {
                 let output = format_time(&_date, dialect);
